How to localize a static UITableView section? - ios

I have a view with a UITableView with one section and one cell. It's used purely for layout. The section has a header and a footer, both with some text in it.
I want to localize this text but can't figure out how. Currently the only way I'm aware of is to implement titleForHeaderInSection: but I'd prefer not to do this as it's a static table, and I'd rather avoid having to implement the UITableViewDelegate just to accomplish this. Is there another way?

If you have implemented UITableViewDataSource, you can use NSLocalizedString when implementing tableView:sectionIndexTitlesForTableView: and tableView:cellForRowAtIndexPath:.
If you are using interface builder, xcode allows you to localize entire xib. But the drawback is that it will create one xib for each locale you need to support.

Related

iOS: Using custom UITableViewCell vs. Using Cell viewWithTag?

Custom Cell For UITableViewCell
I'm developing an iOS application and i need to make a custom cell for my side menu, i have seen so many examples and i found out those two approaches :
Make a class (.h and .m files) that inherits from UITableViewCell and put the outlets in the .h file then apply the class on the cell and connect those outlets to the labels and/or images from your cell in the storyboard.
Or the easy way is to give a tag to the labels/images or whatever you have in the cell in your storyboard.
My Question: I'm wondering which way is more accurate and professional and used by most iOS developers ?
Definitely the first one. It's clear and maintainable in the future. The purpose of the tag is not to store arbitrary values. See my answer regarding this.
This article has some details on the usage of tags

How to convert static UITableView to dynamic TableView

I've got a static TableView that now needs to become a dynamic TableView, because other views need to be placed around the ViewController, and this can not be done using containers in my case.
The question is: how do I efficiently convert the table view from static to dynamic?
I'm aware of having to change the inheritance from UITableView to UIViewController and add the plus the delegate methods.
But how about all of the Table-Sections: I have 3 sections with 6 types of cell in the static table. Do I really need to subclass UITableViewCell for all of these cell-types and deal with everything manually, or is there a more clever way to do this?
You really can't just convert between the two. By merely implementing some of the tables delegate methods, like cellForRowAtIndexPath:, you loose your static content. That being said, the table should be dynamic the entire time. This way, you can define logic to determine whether or not it should show the content that you originally added statically, or the new dynamic content.
Additionally, you don't need a view controller to implement the delegate/datasource methods. If you already have a subclass of UITableView, that's fine. You can set it as its own delegate/datasource, and implement those methods within the subclass.
And to answer your last question, no there really isn't a better way to do that. I recommend that you create one base class that subclasses UITableViewCell that implements everything that the cells will share, and then implement the individual changes in subclasses of this base class. Using multiple cell subclasses in a table view sounds a lot worse then it is.

UITableView with 8 inherited cell type

I have a UITableView, with 8 differents type of cell. Those custom cell have some design in commom (like a upper left icon, a title, a subtitle...). However, under those common features, each cell is different. In order to have less to maintain, my 8 cells inherits from a default abstract cell with the commons IBOutlet.
Now my question is : what is the best, most proper way to do this?
At first, I thought of using registerNib:forCellReuseIdentifier: but this means 8 different xib. In this case, if one of the common design feature change, I would need to go trought all 8 xibs to change the same thing. I thnik it's not very productive and clean.
I thought also of registerClass:forCellReuseIdentifier: but this methods does not create the cell with a nib, so I would need to do everything programmatically.
The solution could be have one common xib, different registered class in the tableview, and those will be responsible for using their own custom design. But I can't see how to achieve this with those two previous methods.
I would use a single nib file with 8 different UITableViewCell subclasses. You should be able to use registerClass:forCellReuseIdentifier: and inside the class (which subclasses UITableViewCell) you make use of the nib file. If it is not clear I'll try to provide some code.

In iOS can a cell in a tableview have more than just a text

Can i have two images and a few text labels in a cell of a tableView ? All dynamically assigned ?
Yes, read the documentation for the UITableViewCell class, specifically the UITableViewCellStyle constants which allow for various types of standard table cells to be created. If the built in styles do not meet your requirements, you can subclass UITableViewCell and create anything you want, since it's just another type of UIView.
Of course you can! There are several ways of achieving that, the most popular being subclass the UITableViewCell class, and creating your own custom cell, and you can have whatever you want in it. But just to get an idea of how to go about doing that, I suggest you go through the following links:
Table View Programming Guide for iOS - Apple
Crafting Custom
UITableViewCells - MobileTuts+

Custom UITableViewCell using storyboard with some cells

I have a TableView in which a most cells are pretty standard. I make them buy using static cells in Storyboard. However, one cell I would like to customize probably using an XIB file so I would need to load it programmatically.
In the TableView's data source, is it possible to handle loading XIB view for this particular cell only, while leaving other cells to what's delineated in the static cells in the Storyboard? Or is it an all or nothing thing where I need to just give up using static cells altogether?
The rationality for doing this is that I would like to make Storyboard to look as close to the real thing as possible. Right now if I provide a data source, the static cells in the storyboard would have no effect on the actual output and is not in any sense linked to the actual output.
Yes, it is possible. Set the custom class for the custom cell. If you wish to customise it from code, just connect it as an IBOutlet to the UITableViewController.

Resources