【发布时间】:2015-04-22 04:11:43
【问题描述】:
如何在objective-c 中将数据从一个视图控制器传递到另一个视图控制器?我知道在swift 中我会在类声明之外创建一个全局变量,但是在objective-c 中,有没有办法将数据从选定的单元格传递到用户选择该单元格时显示的新视图?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BarInfoCell"];
[cell textLabel].text = [[bars objectAtIndex:indexPath.row] objectForKey:@"name"];
NSString *barAddress = [NSString stringWithFormat: @"%@ %@ %@", [[bars objectAtIndex:indexPath.row] objectForKey:@"address"],
[[bars objectAtIndex:indexPath.row] objectForKey:@"state"],
[[bars objectAtIndex:indexPath.row] objectForKey:@"zip"]];
[cell detailTextLabel].text = barAddress;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self performSegueWithIdentifier:@"detailSeg" sender:self];
}
【问题讨论】:
-
为什么要在 Swift 中使用全局变量?语言的选择不应该改变方法。在任何一种语言中,全局变量都是错误的传递数据的方式。
标签: ios objective-c json uitableview global-variables