如何通过 UINavigationController 将数据从我的 UITableViewCell 传输到 UIViewController?例如,我想要做的是将 UITableViewCell 标签名称从单元格传输到 ViewController 的标签。如果你看这两张照片,你就会明白我的意思。另外,另一方面,我通常如何将数据从一个 View 传输到另一个 View ?谢谢
最佳答案
在接收器 View Controller 中
在.h文件中
@interface ViewController : UIViewController
@property (strong, nonatomic) NSString *strDataOfCell;
@end
这里让它变强所以留在内存中
在 TableView 委托(delegate)方法中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"yourViewIdentifer"];
NSString *strData = [self.yourArrayOfData objectAtIndex:indexPath.row]; // Here Put your code to Get value from data source array , which is loaded in tableview
vc.strDataOfCell = strData;
[self.navigationController pushViewController:vc animated:YES];
}
希望对您有所帮助:)
关于ios - 如何将数据从 UITableViewCell 传输到另一个 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36853617/