UITableView with static cells does not appear

2020-01-25 05:08发布

I have created a new Xcode project using Storyboards (tab view template). I added a couple of view controllers to my storyboard, and wanted to use a UITableView with static cells for one. I created it, but when I run in the simulator the cells don't appear. I haven't changed anything in the project except for this storyboard file. I am showing screenshots of the storyboard editor and the simulator running. The label shows up, so the view is loading correctly. I set the background color to gray so I can see the talbeview is loading. All cells are set to visible. I changed their style to Basic and edited the label, and added a disclosure indicator, that's all.

simulator xcode

5条回答
Melony?
2楼-- · 2020-01-25 05:26

I was experiencing the same problem, and the fix that worked for me was to present the static UITableViewController subclass using performSegue. Presenting the old way with [[self navigationController] present...] did not result in the static table view properly loading its cells.

查看更多
欢心
3楼-- · 2020-01-25 05:38

You can add a Container View and embed a UITableViewController in that container. Then you can manage your static cells inside the new controller.

查看更多
在下西门庆
4楼-- · 2020-01-25 05:40

Don't implement any of the methods below when you use the static table view:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}
查看更多
Deceive 欺骗
5楼-- · 2020-01-25 05:40

As stated on Ray Wenderlich's website (in this post: Beginning Storyboards in iOS 5 Part 2, section "The Add Player Screen at Work" ):

One more thing about static cells, they only work in UITableViewController. The Storyboard Editor will let you add them to a Table View object inside a regular UIViewController, but this won’t work during runtime. The reason for this is that UITableViewController provides some extra magic to take care of the data source for the static cells. Xcode even prevents you from compiling such a project with the error message: “Illegal Configuration: Static table views are only valid when embedded in UITableViewController instances”.

Had the same issue but this makes things clear...

查看更多
别忘想泡老子
6楼-- · 2020-01-25 05:45

Do you want to try using the TableViewController rather than the Generic View controller ?

查看更多
登录 后发表回答