xlform custom rows using nibs - ios

I want to use XLFormSelectorCell but I need to customize the UI in a nib file. How do I do this? Can I just create a subclass from XLFormSelectorCell instead of XLFormBaseCell or do I really need to rewrite all the methods in XLFormSelectorCell? Can you show me the best way to do it? Thanks!

It is clearly mentioned with example in this link.
All you need to do is just create a custom cell of type XLFormBaseCell and then manipulate the data according to your requirement

In the overridden +load method of your custom cell, you need to add your cell in the XLFormViewController.cellClassesForRowDescriptorTypes dictionary. But, when using nibs, instead of the class, you should use a string containing the nibName.
For example:
[XLFormViewController.cellClassesForRowDescriptorTypes setObject:#"nibName" forKey:#"XLFormRowDescriptorYourCustomType"]

Related

How to properly subclass an existing row

I'm needing help in correctly subclassing an existing row so I can change the UI only, not the function. The type of row I'd like to subclass is TextRow.
Again, I only want to change the UI and not the functionality.
Eurek mentions here a way to do it but I can't seem to figure out the correct way to do it. I'd like to form rows look like this.
The steps according to Eureka:
Subclassing cells using the same row
Sometimes we want to change the UI look of one of our rows but without changing the row type and all the logic associated to one row. There is currently one way to do this if you are using cells that are instantiated from nib files. Currently, none of Eureka's core rows are instantiated from nib files but some of the custom rows in EurekaCommunity are, in particular the PostalAddressRow which was moved there.
What you have to do is:
Create a nib file containing the cell you want to create.
Then set the class of the cell to be the existing cell you want to modify (if you want to change something more apart from pure UI then you should subclass that cell). Make sure the module of that class is correctly set
Connect the outlets to your class
Tell your row to use the new nib file. This is done by setting the cellProvider variable to use this nib. You should do this in the initialiser, either in each concrete instantiation or using the defaultRowInitializer. For example:
<<< PostalAddressRow() {
$0.cellProvider = CellProvider(nibName: "CustomNib", bundle: Bundle.main)
}
You could also create a new row for this. In that case try to inherit from the same superclass as the row you want to change to inherit its logic.
There are some things to consider when you do this:
If you want to see an example have a look at the PostalAddressRow or the CreditCardRow which have use a custom nib file in their examples.
If you get an error saying Unknown class <YOUR_CLASS_NAME> in Interface Builder file, it might be that you have to instantiate that new type somewhere in your code to load it in the runtime. Calling let t = YourClass.self helped in my case.
Basically what I need help with is setting up the correct xib/nib and class to use within the form. Thank you.

How to localize a static UITableView section?

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.

Implementing a form within a TableView

I would like to implement a form to insert data within a TableView in my app.
I would like the form appears as a table, and each row of the table represent a TextField.
What is the right approach to do this?
Any help is appreciated!!
Regards, yassa
If I understood your question right then I would go for custom TableViewCells.
Subclass UITableViewCell.
In the init method (initWithStyle, if I am not much mistaken) create the Text Fields and add them to the superview. ([self.view addSubView:myTextField])
In the layoutViewItems method you should arrange the TextField and any other custom view that you may want to create and add in init.
While overwriting both of them, do not forget to call the related superclass method at the very beginning. You may not need [super layoutSubviews] in the event that you do not want to use any of the standard elements of UITableViewCell.
If you are using Storyboard, use the new Static Cell TableView (as opposed to Dynamic Prototypes. This allows for a TableView that you don't have to use the delegate or datasource methods on. You can layout the sections and rows manually in IB. I use it lots for form based views.

Using to different delegate method for the same picker?

Im trying to create a view with two pickers, each with multiple components, one of the pickers has 4 components that are all text based, the other has two components that need to display graphics and two that need to display text. Is there any way to use the pickerView:titleForRow:forComponent:(NSInteger)component delegate method and the pickerView:viewForRow:forComponent:reusingView: delegate method for the same picker?
I've implemented both, only the viewForRow one seems to ever get called. Do I need to just use that one and create a view with a label for each row?
You can create one picker, yes, or you can implement one common method for both pickers and determine what picker is calling it by checking it's tag.
The Solution I cam up with was to call pickerView:titleForRow:forComponent: from pickerView:viewForRow:forComponent:reusingView: and create a UILabel with the string from the first method. It works, but it seems like there ought to be a better way.

Can I use more than one custom tableviewcell nib file in a UITableView?

I want to put different cells in a table, and all of them is kind of complexity, so I want to use nib for these cells. However, i really don't know how to use multiple cells in a table. Can you help me?
You can use as many custom UITableViewCells as you want in a single UITableView. The issue here is: What kind of logic do you want to implement? Only you can define it. You can start by using this tutorial to see how to implement the custom UITableViewCells:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
You can then reply to my answer to tell me what logic do you to implement. For example:
first 3 cells one with a type of UITableViewCell, then 3 with different UITableViewCell.
Alternate between cells (for instance, 4 different UITableViewCells in a row)
You need to specify what you need. :)

Resources