按下按钮后加载表格视图笔尖 [英] Loading a table view nib after button push
问题描述
我已经使用以下代码在导航栏中添加了一个按钮,按下该按钮将调用showCountries方法:
I have used the following code to add a button to my navigation bar that when pressed will call the method showCountries:
UIBarButtonItem *countriesButton = [[UIBarButtonItem alloc] initWithTitle:@"Countries" style: UIButtonTypeRoundedRect target:self action:@selector(showCountries:)];
self.navigationItem.leftBarButtonItem = countriesButton;
[countriesButton release];
现在可以正常工作了,该按钮将出现,按此按钮将按计划进入showCountries方法.
Now this works, the button appears and when pressed goes to the showCountries method as planned.
显示国家/地区方法需要做的是加载一个新的表格视图,其中包含一个错误国家/地区列表(目前位于一个数组中).
What the show countries method needs to do is load a new table view containing a list of err countries (which at the moment are in an array).
为此,我尝试了以下代码:
To do this I have tried the following code:
UIViewController *controller = [[UIViewController alloc] initWithNibName:@"countriesViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
一切似乎都可以正常编译,但是使用时,控制台中会出现以下错误,并导致应用崩溃:
All seems to compile fine but when used the following error appears in the console and boom the app crashes:
2010-06-21 18:09:02.076增值税Pro [788:207] *-[UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例0x12a920 2010-06-21 18:09:02.082 Vat Pro [788:207] * 由于未捕获的异常'NSInvalidArgumentException'终止了应用程序,原因:'***-[UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例0x12a920' 2010-06-21 18:09:02.088增值税Pro [788:207]
2010-06-21 18:09:02.076 Vat Pro[788:207] * -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x12a920 2010-06-21 18:09:02.082 Vat Pro[788:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x12a920' 2010-06-21 18:09:02.088 Vat Pro[788:207]
我已经挠头2天了,请讨价还价,请告诉我.
I have been scratching my head for 2 days now so pleeeeease if you can spot my mistake please tell me.
我还尝试加载普通的nib文件,效果很好.
I also tried loading a plain nib file and this worked fine.
推荐答案
是-我发现了问题.这是因为我从第一个内部声明了第二个视图控制器,然后释放了它.此后,我将其移至我的应用程序代表,该代表已解决了该问题.
Yea - I found the problem. It was because I was declaring the 2nd view controller from within the first and then releasing it. I have since moved this to my app delegate which has resolved the problem.
我创建了一个测试项目,演示了其他任何人都认为有用的项目. 链接文本
I have created a test project demonstrating this should anyone else find this useful. link text
这篇关于按下按钮后加载表格视图笔尖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!