Add more than one SearchBar in tableView - ios

It's possible to add two searchBar's in one View controller. For example, I have a static table view with two rows, in each row I want to have UITableViewCell with searchBar. I can't find any way how can I do this in the Net. It's possible?

The answer is YES. You can place as many UISearchBars as you want. Create a custom UITableViewCell and place a UISearchBar inside of it.

Related

UITableView Inside a UICollectionView

How can I set multiple table view data inside a collectionView?
I think its too complex to add multiple table views inside one UICollectionViewCell. Embedded scroll views is not recommended in terms of UX.
But you can do it by subclassing The UICollectionViewCell and be the delegate/datasources of table views.
You can use only one table with multiple sections instead of multiple tables.
You can achieve this by giving tag to each UITableView in all the UICollectionViewCells and you have to manage all UITableViewDataSource and UITableViewDelegate methods by tags of particular tableView.
I know its complicated but you can try this out.

How to reuse UITableViewCells

I have 2 viewcontrollers on my storyboard, which both have a tableview. Now I would like to implement the same cells in both tableviews. Is there a way to easily reuse these cells across multiple viewcontrollers?
Yes you can use it by using custom table view cell
Example for custom table view cell
You should reuse full UITableView for this case. There is no open API for sharing cells between multiple UITableViews, but you still can reuse UITableView in case there is no moment when two controllers are shown simultaneously.
Yes, It's possible you need to create .nib file with subclassing UITableviewCell
take a look on https://medium.com/#musawiralishah/creating-custom-uitableviewcell-using-nib-xib-files-in-xcode-9bee5824e722#.u8xounci2
you get to know , how to create & use .nib file.

Change another cell in dynamic prototype UITableView when a switch in one cell change

I used to use static UITableView but the table is too long and overflow the memory.
I switched a dynamic prototype UITableView with 1 type of cell, which has an UISwitch in it.
One of the cell, when turning on the switch, will turn off the switch of another cell. These cells have fixed index.
The IBAction method is in my UITableViewCell subclass and I don't want to add the UITableView as a property in my UITableViewCell.
How do I achieve the above effect?
I'm planing to use an id or similar to distinguish between the cells as each cell's switch has different effects, that doesn't solve the above requirement.
Thanks,
I would add a block property to your cell which you can use to notify your controller of changes in the switch. See my answer below to a question on this:
How can I get index path of cell on switch change event in section based table view
All your logic can now be implemented in the view controller.
You are best to create a data model in the view controller which the cells simply provide views and controls onto. When you flick one switch and the block fires, update the data model and simply reload the table. Any cells affected will show the new data model positions for their switches. Avoid using one cell to adjust another. Just update the model and reload the cells.

UITableViewCell next to eachother

How can i make a tableview where the cells are next to each other. Where there are 2 on each row. example like this? In the second row there are 2 images next to each other. Can this be done in a tableview by making custom tablevieCells?
Yes this can be done in UItableViewCell But preferred to use collection view for this kind of view.
Just subclass uitableviewcell, add new method
-(void)setCellWithNumberOfImages:(NSInteger)images withImage1:(UIimage *)image1 withImage2:(UIImage *)image2;
if(image2 ==nil)
//add only one UIimageView with image1
else
//add two imageviews.
You need to use a UICollectionViewController (https://developer.apple.com/library/ios/documentation/uikit/reference/UICollectionViewController_clas/Reference/Reference.html)
Using a UICollectionView you can implement a custom layout which layouts the elements as in your screenshot
You can Use UICOllectionView That's much easier and customizable, you can chose how many item you want to have in a row and size for example.
for more information please check: UICollectionView Class Reference

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.

Resources