简体   繁体   中英

FirstViewController tableView:numberOfRowsInSection:] error with Static Cells

I'm making an app with a table view with static cells. In the storyboard, the table has labels and switches. However, when I try run the program on the simulator, I get the following errors:

"FirstViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance"

and

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

I tried implementing the following methods (even though it seems as if I don't need to since I'm using static cells):

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

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

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

However, when I ran the app, I got a blank table.

Can anyone advise? I am pretty new to iOS programming, so any help would be extremely appreciated.

Thanks,

Jordan

UPDATE:

I think my problem is that I am using static cells without a UITableViewController. Is there any way I can use static cells without a UITableViewController?

Connect the " dataSource " of your table view (in the XIB or Storyboard file) to point to your view controller and see if you have better luck.

Also, make sure your FirstViewController.h conforms to the " UITableViewDataSource " protocol. In your .h file, it should look like this:

@interface FirstViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

The "delegate" declaration there also means your view controller can handle any delegate methods also, provided you connect the table view to your controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM