TableView数据传递给其他tableView和导航控制器

时间:2013-12-23 20:34:37

标签: ios iphone objective-c uitableview

首先,我尝试了所有segue代码但不是真正的结果......

iOS 7 )我的故事板以Tab Bar开头,并有一个Button to Model - >带导航控制器的表视图。 TableView具有JSON数据。如果单击一个单元格,则使用push segue传递给另一个tableViewController。 我的推送代码:

KatAltViewController * ilet = [[KatAltViewController alloc] init];
    Kategoriler * currentKategoriler = [kategorilerArray objectAtIndex:indexPath.row];
    ilet.cid = currentKategoriler.cid;
   [self.navigationController pushViewController:ilet animated:YES];

第一个tableView没有问题,但如果单击一个单元格到第二个表视图,控制台会给出错误:

2013-12-23 17:08:59.871 project02[3903:70b] nested push animation can result in corrupted navigation bar
2013-12-23 17:09:00.238 project02[3903:70b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

所以,我在第二个tableview中点击Back按钮:屏幕是黑色的!

2013-12-23 17:10:34.081 project02[3903:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't add self as subview'

我如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

如果您的故事板中已有NavigationController,并且您使用此代码

[self.navigationController pushViewController:ilet animated:YES];

你拨打2次NavigationController

那你可以尝试这个代码部分吗?

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


    passElement=[array1 objectAtIndex:indexPath.row];
    [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(passToOtherTableView) userInfo:nil repeats:NO];


}
-(void)passToOtherTableView{

    [self performSegueWithIdentifier:@"passSegue" sender:self];

}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"passSegue"]){
        SecondTableViewController *controller = (SecondTableViewController *)segue.destinationViewController;
        controller.value = passElement;
    }
}

我希望这对你有帮助。

答案 1 :(得分:0)

感谢所有答案。 是@ TwentyThr23,我叫了两次NavigationController ...

我删除了这些代码,因为我已经在故事板上推送了单元格;

KatAltViewController * ilet = [[KatAltViewController alloc] init];
Kategoriler * currentKategoriler = [kategorilerArray objectAtIndex:indexPath.row];
ilet.cid = currentKategoriler.cid;
[self.navigationController pushViewController:ilet animated:YES];

我添加了这些行;

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  if ([segue.identifier isEqualToString:@"altKategoriS"]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    KatAltViewController *destViewController = segue.destinationViewController;
    Kategoriler * currentKategoriler = [kategorilerArray objectAtIndex:indexPath.row];
    destViewController.cid = currentKategoriler.cid;
  }
}