- 在 tableview:didSelectRowAtIndexPath: 方法中获取被选中的单元格数据:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *rowData = [_dataArray objectAtIndex:indexPath.row];
AnotherViewController *vc = [[AnotherViewController alloc] init];
vc.dataDict = rowData;
[self.navigationController pushViewController:vc animated:YES];
}
- 在另一个视图控制器中定义一个属性来接收传递的数据,并在 viewDidLoad 或 viewDidAppear 方法中使用该数据:
@interface AnotherViewController : UIViewController
@property (nonatomic, strong) NSDictionary *dataDict;
@end
@implementation AnotherViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%@", self.dataDict);
}
@end