iphone - 将 NSString 发送到另一个 UIViewController 给出 null

标签 iphone ios uinavigationcontroller nsstring

很简单,但我真的不知道为什么它总是给我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/

相关文章:

ios - 无法在 ViewController 的 AppDelegate 中使用数组

javascript - stringByEvaluatingJavaScriptFromString 不起作用

ios - 如何监听 Firebase 任务完成?

ios - 带登录的 Iphone 应用程序

iOS7 UIModalTransitionStyleFlipHorizo​​ntal 在过渡后反弹

iphone - 左右滑动 UIView

iphone - 检测对象上的坐标并将其输出到 NSLog

ios - UIToolbar 色调颜色不起作用

ios - ViewForHeaderInSection 中的两个 header

swift - 以编程方式更改 View