ios - 如何将数据从 UITableViewCell 传输到另一个 UIViewController?

标签 ios objective-c iphone uitableview uiviewcontroller

Cell New View

如何通过 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/

相关文章:

iphone - 从 UIColor 预设中获取 RGB 值

ios - 如何像在堆栈中一样插入数字并像弹出一样删除

ios - UIScrollView-zoomToRect :animated: and CGPoint conversion between views

iphone - 无法在 View 之间读取 NSUserDefaults 数据

iphone - 当用户单击 Thumb ViewController 中的拇指时如何显示自定义 View ?

ios - 自动将其中的自定义 UITableViewCell 和 Label 调整为文本

由于搜索显示 Controller 检测到僵尸,iOS 7 应用程序崩溃

ios - 如何对NSString中的成分进行排序?例如1/2杯牛奶,1/4勺粉

objective-c - 从 UIViewController 内部在 iOS objective-c 中绘制 4.000 个点或线

iOS( swift ): Core data transformable attributes