当你点击一个UITableView 的section 或者cell的时候希望把值传到另一个页面(页面是通过segue跳转的),可以通过prepareforsegure 方法传值

(我的UITableView Controller 添加了NavigationController)

示例代码如下:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    
    UIViewController *controller;
    if ([segue.destinationViewController isKindOfClass:[UINavigationController class]]) {
        UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
        controller = [navController.viewControllers objectAtIndex:0];
    } else {
        controller = segue.destinationViewController;
    }
    
    if ([controller isKindOfClass:[NewsDetailViewController class]]) {
        NewsDetailViewController *detailController = (NewsDetailViewController *)controller;
        NSIndexPath *selectIndexPath = [self.mainTableView indexPathForSelectedRow];
        //[detailController setDataString:[NSString stringWithFormat:@"%i",selectIndexPath.section]];
        [detailController setDataString:[self.dataArray objectAtIndex:selectIndexPath.section]];
    } else {
        NSAssert(NO, @"Unknown segue. All segues must be handled.");
    }
    
}

原文出处:http://blog.csdn.net/wildcatlele



相关文章:

  • 2021-12-08
  • 2022-12-23
  • 2021-05-24
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
相关资源
相似解决方案