2012-10-24 60 views
0

我試圖從TableViewCell數據傳遞到另一個ViewController.But在另一ViewController.here沒有數據顯示的是我的代碼錯誤推TableViewCell到其他的ViewController

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


    PeripheralManager *objSelected=[device objectAtIndex:indexPath.row]; 

    [self prepareForSegue:@"TableDetails" sender:objSelectedDevice]; 
} 


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 


    if ([segue.identifier isEqualToString:@"TableDetails"]) 
    { 


    DetailViewController *detail=segue.destinationViewController; 
    detail.dataArray=device; 
    } 

} 

錯誤消息

nested push animation can result in corrupted navigation bar 
2012-10-24 12:01:39.805 [3182:707] nested push animation can result in corrupted navigation bar 
2012-10-24 12:01:40.164 [3182:707] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted. 
2012-10-24 12:01:40.167 [3182:707] Finishing up a get navigation transition in an unexpected state. Navigation Bar subview tree might corrupted. 
+0

看起來你是在調用seque兩次。你是否在Storyboard **中設置了它,以及在'didSelectRowAtIndexPath:'方法中設置了它? – Abizern

回答

1

刪除您額外的代碼只有做到這 -

DetailViewController.h

@property(nonatomic, retain)NSMutableArray *dataArray; 

DetailViewController.m

@synthesize dataArray = _dataArray; 

現在TableViewController.m只要寫這 -

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if([segue.identifier isEqualToString:@"TableDetails"]) 
    { 
    DetailViewController *detailViewObject = segue.destinationViewController; 
    detailViewObject.dataArray = anyArray; 
    } 
} 

我在這裏通過NSMutableArray

-1

它可能有一些做這一行:

[UIView commitAnimations]; 

你可以去如果你不需要它,就會用它。

+0

沒有更改同樣的錯誤顯示 – prem

4

你不需要這樣的:

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

這就是Segue會自動完成

而且,你有3條線將加載視圖控制器 - 見下面的意見:

NSInteger row=[indexPath row]; 
NSString *value=[device objectAtIndex:row]; 
MeBleDetailViewController *mdc=[self.storyboard instantiateViewControllerWithIdentifier:@"MeBleDetailViewController"]; 
mdc.deviceName=value; 
[self presentModalViewController:mdc animated:YES]; // Load ViewController 
[UIView commitAnimations]; 
[self performSegueWithIdentifier:@"TableDetails" sender:[device objectAtIndex:indexPath.row]]; // Load ViewController 
[self.navigationController pushViewController:mdc animated:YES]; // Load ViewController 

這就是爲什麼你會得到該錯誤:嵌套的推動動畫會導致損壞的navigati

此外,如果您已將表單元格中的segue配置到另一個視圖控制器,那麼您在didSelectRowAtIndexPath方法中不需要任何東西。


編輯:

無論數據你想要的推視圖控制器有 - 把它放在prepareforSegue方法,而不是didSelectRowAtIndexPath

如果從表單元格中創建一個SEGUE查看控制器,那麼你不要由於此方法是以編程方式執行segue,因此不需要執行以下操作。

[self performSegueWithIdentifier:@"TableDetails" sender:[device objectAtIndex:indexPath.row]];

+0

沒有更改同樣的錯誤顯示 – prem

+0

我已經更新了我的答案。檢查這3行,看看你真正需要哪一行。 – user427969

+0

是correct.what是什麼意思非平衡調用開始/結束外觀轉換 – prem

1

好的。假設您有兩個視圖控制器FirstViewControllerSecondViewController。 在FirstViewController你有一個tableview,當然tableviewcell。在SecondViewController中,您需要顯示數據。 因此在SecondViewController.h中,您需要設置一些變量的索引,在這種情況下,它是id類型@property (strong, nonatomic) id secDetailItem;。合成它在SecondViewController.m並添加setter方法這樣

-(void)setDetdetailItem:(id)newSecdetailItem{ 
if (secDetailItem != newSecdetailItem) { 
    secDetailItem = newSecdetailItem; 

    // Update the view. 
    [self configureView];//This method is needed to update view if there are some changes in that view. 
} 
} 

所以後來在FirstViewController.h進口SecondViewController.h,並添加屬性@property (strong, nonatomic) SecondViewController *secondViewController;然後 合成。在FirstViewController.m文件在此委託方法做如下:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
self.secondViewController.secDetailItem=//set your data should be passed. 

//如果你還需要推動的ViewController添加pushviewcontroller:SecondViewController,或者使用IB來的tableview細胞和SecondViewController與推送方法連接在一起。 }

在這種情況下,您不需要使用執行segue。Setter方法一旦設置爲secDetailItem就會工作。

此外,如果您需要更新您的視圖SecondViewController添加此方法。

- (void)configureView 

{

if (self.secDetailItem) { 
    self.textLabel.text=self.secDetailItem;//Data passed from FirstViewController 
} 

}

這是所有你需要做的。很抱歉,如果它很複雜。詢問任何問題。

+0

你可以寫[secondViewController setSecDetailItem:];也:) :) – Charan

+0

耶是一樣的。在這兩種情況下,你調用相同的方法。 – Garnik

相關問題