Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 目标C-将JSON数据从Tableview传递到另一个视图控制器_Ios_Objective C_Iphone_Json_Uitableview - Fatal编程技术网

Ios 目标C-将JSON数据从Tableview传递到另一个视图控制器

Ios 目标C-将JSON数据从Tableview传递到另一个视图控制器,ios,objective-c,iphone,json,uitableview,Ios,Objective C,Iphone,Json,Uitableview,JSON数据: ({ CustDisplayName = "John Doe"; CustID = 2; }, { CustDisplayName = "Jane Doe"; CustID = 21; }) 在tableview上显示数据,就像一个联系人列表正在工作一样,并且还显示从单元格到其他视图的分段(推送) - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NS

JSON数据:

({

    CustDisplayName = "John Doe";
    CustID = 2;
},
    {
    CustDisplayName = "Jane Doe";
    CustID = 21;
})
在tableview上显示数据,就像一个联系人列表正在工作一样,并且还显示从单元格到其他视图的分段(推送)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath 
*)indexPath {
    [self performSegueWithIdentifier:@"pushDetailView" sender:indexPath];
}
现在我正在通过prepareForSegue传递数据

if ([[segue identifier] isEqualToString:@"pushDetailView"]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

    NSLog(@"%@", indexPath);
}
日志只显示0,1,2,3,这不是我想要的。我不确定什么是最好的方法

  • 选择行get CustID并对另一个视图的viewDidLoad执行另一个请求
  • 选择行获取该数组并将字符串传输到另一个视图

  • 我是iOS开发新手,希望有人能提供帮助。

    在目标ViewController的头文件中,定义一个名为dict.的NSDictionary类型属性,并将Json数据解析为一个数组,其中包含NSDictionary对象

    if ([[segue identifier] isEqualToString:@"pushDetailView"]) {
       UIViewController *controller = segue.destinationviewcontroller;
       controller.dict = [array objectAtIndex:indexPath.row].
    }
    

    我想您需要的是
    indepath.row
    而不是
    indepath

    假设您的数据源是一个
    NSArray
    填充了
    Customer
    对象

    首先,在详图viewController中创建客户属性:

    @property (nonatomic,strong) Customer customer;
    
    然后,在选择行时必须设置此属性。为此,请使用
    prepareForSegue
    方法:

    -(void) prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
    {
       if ([[segue identifier] isEqualToString:@"pushDetailView"]) {
          DetailViewController*destination= segue.destinationviewcontroller;
          NSIndexPath* indexPath = [tableView indexPathForCell:sender];
          destination.customer = datasource[indexPath.row];
       }
    }
    
    确保在调用performsgue时将单元格设置为发件人。 确保这一点的一种方法是从故事板创建您的segue,而不是手动执行


    您可能还想使用它来轻松解析JSON:

    试试看,这确实提供了答案,我相信上面的帖子中有人想打印选中的行,可以使用“indexPath.row”而不是“indexPath”来获得。嗨,罗杰·范,谢谢你提出,但Chandan005是正确的。它实际上在某种程度上是有帮助的。干杯,伙计们。