UITableView in each tab

百般思念 提交于 2019-12-12 05:57:34

问题


I'm currently developing a tab bar based application with 5 tabs that have an UITableView each. Each tab is linked to a normal UIViewController, the first two with the ones that xCode creates by default and the others with the ones I created. If I try to add a table view to the first two view controllers (default ones) everything works smoothly, but when I do the same with the others, the app crashes telling me that:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x4e2f6f0'    

and the tableView:numberOfRowsInSection: in my .m file is this:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;

}

do you now any solution ? I've looked around with no result

thanks in advance for answers


回答1:


Check those two things.

1) if your other viewControllers are subclasses of UIViewController then they should implement the delegate methods:UITableViewDelegate and UITableViewDataSource. Meaning it is not only required to implement them in your code but to tell the compiler that you will.

@interface thirdViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

2) or try to see if your viewController is of type UITableViewController.

@interface thirdViewController : UITableViewController



回答2:


Please watch this tutorial. http://www.youtube.com/watch?v=LBnPfAtswgw



来源:https://stackoverflow.com/questions/5927661/uitableview-in-each-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!