objective-c - 将 TableViewCell 推送到另一个 ViewController 时出错

标签 objective-c ios uitableview ios5.1

我试图将数据从 TableViewCell 传递到另一个 ViewController。但是另一个 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.

最佳答案

你不需要这个:

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

这就是 Segue 会自动执行的操作

此外,您有 3 行将加载 View Controller - 请参阅下面的注释:

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

这就是您收到该错误的原因:nested push animation can result in corrupted navigation bar

此外,如果您已经配置了从表格单元格到另一个 View Controller 的 segue,那么您不需要在 didSelectRowAtIndexPath 方法中做任何事情。


编辑:

无论您希望推送的 View Controller 拥有什么数据 - 将其放在 prepareforSegue 方法中而不是 didSelectRowAtIndexPath

如果您创建一个从表格单元格到 View Controller 的转场,那么您不需要执行以下操作,因为此方法是以编程方式执行转场。

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

关于objective-c - 将 TableViewCell 推送到另一个 ViewController 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13042932/

相关文章:

ios - 如何增加 MDCTextInputControllerOutlinedTextArea 的高度

objective-c - 以编程方式在另一个桌面(空间)中打开 NSWindow

objective-c - iOS 8 快照尚未呈现的 View 会导致空快照

ios - 在 iOS 7 中,使用 UIModalPresentationCurrentContext 进行动画模式演示不会设置动画

swift - 如何使单元格及其元素显示为灰色?

ios - 如何使用 'map' 将 Realm 集合更改通知映射到 UITableview 部分?

ios - Swift-TableView中的按钮崩溃

ios - 在 NavigationBar 中单击 UISearchBar 时没有任何反应

ios - 如何只更新 UITableViewCell 的一个元素?

ios - SCNActionTimingModeEaseInEaseOut 的使用