很简单,但我真的不知道为什么它总是给我null。
- FirstViewcontroller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[_tableView deselectRowAtIndexPath:indexPath animated:YES];
SubViewViewController *viewTwo = [[SubViewViewController alloc] initWithNibName:@"SubViewViewController" bundle:[NSBundle mainBundle]];
viewTwo.queryValue = [NSString stringWithFormat:@"%d",indexPath.row];
[self.navigationController pushViewController:self.subViewController animated:YES];
}
- SecondViewcontroller.h:
NSString *queryValue;
@property (nonatomic, retain) NSString *queryValue;
- SecondViewcontroller.m:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@", self.queryValue);
}
最佳答案
在你的代码中你做错了你应该初始化你推送到 navigationController 的 viewController,你正在初始化 viewTo
但你正在推送 self.subViewController
。
应该是这样初始化的;
self.subViewController= [[SubViewViewController alloc] initWithNibName:@"SubViewViewController" bundle:[NSBundle mainBundle]];
关于iphone - 将 NSString 发送到另一个 UIViewController 给出 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15837211/