storyboard傳值方式

經過segue傳值 在storyboard設置segue的Identifier
 
segue是鏈接兩個視圖控制器交互的線
sender是觸發這個方法執行的對象,好比是單擊tableView上的cell跳到下一界面  那麼這個cell就是sender
//此方法在表視圖控制器.m文件中最下面
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.
   //將當前位置的jid賦值給要跳轉的視圖控制器的的jid屬性 if ([segue.identifier isEqualToString:@"push"]) { UITableViewCell *cell = sender; ChatTableViewController *chatVC = segue.destinationViewController;//跳轉的下一界面 NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];//獲取位置信息 XMPPJID *jid = self.dataArray[indexPath.row];//根據位置信息找到數據 chatVC.jid = jid; } }
相關文章
相關標籤/搜索