ChatGPT解决这个技术问题 Extra ChatGPT

UITableView with static cells does not appear

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.

https://i.stack.imgur.com/H0fNf.png


K
Kristian Glass

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
{
}

This means you have to delete implementations at all, not just insert empty methods :)
Yep, but I wonder how to get rid of the Xcode warning that now says the implementation is incomplete?
@wcochran I would check if you're declaring those methods in your interface or if your class is not a subclass of UITableViewController. Both of those could lead to "Incomplete implementation" warnings in this case.
Thank you so much!! Being brand new to iOS development I've been following tutorials and seemingly none of them mention this...of course they mostly work with dynamic tables instead of static ones.
Useful when you have to implement an unwind segue on static cells.
E
EeKay

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...


So is there any way at all of using static cells in a UITableView which is inside a UIViewController using storyboards without embedding the UITableView in a UITableViewController in the storyboard?
from what i read in Ray's part is that this is being prevented because of a check and the illegal configuration alert. So although I am not sure i would bet my money on: No.
@KarenAnne....don't use static cells. Just use a dynamic UITableView and make the container UIViewController a delegate and then use whatever static array you have to populate the UITableView.
XCode actually let me compile and run my app with a tableview inside a UIViewController. It was just a blank table. The Illegal Configuration error message would've helped
I was also able to compile with no error to be faced with a blank table.
D
Dennis Mathews

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


although i can't figure out how to get the table view to work if it's just a subview of a larger view, like in my screenshot. if i drag a Table View Controller over and let it be the whole screen, that works. but if i want to mix and match other UI elements, i have no idea. i can't figure out how to hook it up to a table view controller.
You're only able mix and match only if you embed the table view controller inside a container view that's a child of your larger view.
I had the same problem and it was because the darn generic UIViewController is defaulted to be the parent of the table view when dragging a UINavigationController from the menu. Why not load in a UITableViewController by default Apple? >_<
z
zqy

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


Wow! That's why! I broke my brain, to figure out, why the former developer place UITableViewController in Container!
d
dave

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.