iOS - “UIViewController from storyboard ”Main", but didn't get a UITableView

喜你入骨 提交于 2019-12-13 09:36:06

问题


I have an UIViewController which has UITableView in it. Everything works fine. In "didSelectRowAtIndexPath" methos I want to activate a "show" segue to UIViewController. I set it in Storyboard, created its ViewController class etc.

When I choose the cell, I get an error saying:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] instantiated view controller with identifier "UIViewController-ndM-tm-7SM" from storyboard "Main", but didn't get a UITableView.'

Interestingly, I found that although I put a ViewController to the storyboard, it's changing to Table View Controller by itself. It's picture:

Tis is not initial situation, at first i checked the same place and there were only ViewController. Probably this is the problem.

I looked the same question asked before but they are different. My root view controller is not table view controller, it's view controller including table view.

Anyway, what should i do to handle this? I use prepareForSegue method either and it seems that there's nothing wrong about it.

Thanks!


回答1:


You definately can create a segue from a VC to another VC, and call it from didSelectRowAtIndexpath

I've tried to create a segue from the rootViewController (not the cell) to the detailViewController, it works fine.

First, make sure you have connected the dataSource and delegate in storyboard.

Then connect the segue,

Then in your didSelectRowAtIndexPath method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self performSegueWithIdentifier:@"show" sender:[tableView cellForRowAtIndexPath:indexPath]];
}

And this should be working.




回答2:


you must inherit UITableViewController not UIViewController

write your .h file like this way

@interface ViewController : UITableViewController
//your property & method add here
@end


来源:https://stackoverflow.com/questions/40024078/ios-uiviewcontroller-from-storyboard-main-but-didnt-get-a-uitableview

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