2013-12-23 29 views
0

首先,我嘗試了所有賽格瑞代碼,但不正確的結果......的TableView數據傳遞給其他的tableView和導航控制器

的iOS 7)我的故事板與標籤欄開始,有一個按鈕型號 - >與導航控制器的表視圖。該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. 

所以,我點擊後退按鈕,在第二個實現代碼如下:屏幕是黑色的!

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

我該如何解決這個問題?

+0

您是否還有附加到按鈕或表視圖單元格的segues?如果它是故事板中的一個場景,則不應該使用alloc init來獲取KatAltViewController的實例。你應該使用instantiateViewControllerWithIdentifier:或使用segue。 – rdelmar

回答

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; 
    } 
} 

我希望這可以幫助你。

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; 
    } 
} 
相關問題