質問

I'm trying to add (or have) a navigation bar (or items) on the top of a View controller and and a tableview right below the navigation bar. The problem I'm having is when I set the tableview's datasource to View Controller, my app will crash (setting the tableview's delegate to View controller doesn't). For now, the code for the tableview are in the default ViewController.m. Do I have the tableview's code in the right place or did I connect something improperly?

Here's the error that it gives me:

2013-10-10 15:14:48.442 SomeApp[15058:a0b] -[UIViewController >tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x8d42450 2013-10-10 15:14:48.450 SomeApp[15058:a0b] *** Terminating app due to uncaught exception >'NSInvalidArgumentException', reason: '-[UIViewController >tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x8d42450'

Current setup

役に立ちましたか?

解決

Make sure your view controller adheres to the proper protocols:

CustomViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

And add the necessary methods from these protocols to your implementation. These are the documentation links for your ease:

UITableViewDelegate Protocol Reference

UITableViewDataSource Protocol Reference

他のヒント

You are missing some methods that are required for your tableview to work,

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

More information on UITableViewDataSource Protocol Reference

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top