如何使用UINavigationController在视图之间传递数据 [英] How do you pass data between views using a UINavigationController

查看:99
本文介绍了如何使用UINavigationController在视图之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试使用下面示例中列出的显而易见的方法,但在加载视图中的viewDidLoad上,我传递的变量( rootcategory )仍然为 nil

http ://www.iphonesdkarticles.com/2008/08/table-view-tutorial-part-3.html



这是我的代码:

  CategoryViewController * viewController = [[CategoryViewController alloc] initWithNibName:@CategoryViewControllerbundle:[NSBundle mainBundle] 
self.categoryViewController.rootCategory = @433;
self.categoryViewController = viewController;
[viewController release];

我在标题中合成一个属性如下:

  @property(nonatomic,readwrite)NSString * rootCategory; 


解决方案

您正在分配viewController,

  CategoryViewController * viewController = [[CategoryViewController alloc] initWithNibName:@CategoryViewControllerbundle: NSBundle mainBundle]]; 
viewController.rootCategory = @433;
self.categoryViewController = viewController;
[viewController release];

应该可以正常工作。


I have tried using the obvious method as outlined in the following example but my passed variable (rootcategory) is still nil on viewDidLoad in the loaded view

http://www.iphonesdkarticles.com/2008/08/table-view-tutorial-part-3.html

This is my code:

CategoryViewController *viewController = [[CategoryViewController alloc] initWithNibName:@"CategoryViewController" bundle:[NSBundle mainBundle]];
self.categoryViewController.rootCategory = @"433";
self.categoryViewController = viewController;
[viewController release];

I am synthesizing a property in the header as follows:

@property (nonatomic, readwrite) NSString *rootCategory;

解决方案

You are allocating viewController, and try to change self.categoryViewController before it is assigned to viewController.

CategoryViewController *viewController = [[CategoryViewController alloc] initWithNibName:@"CategoryViewController" bundle:[NSBundle mainBundle]];
viewController.rootCategory = @"433";
self.categoryViewController = viewController;
[viewController release];

should work.

这篇关于如何使用UINavigationController在视图之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆