Load a nib into an UIView? - iphone

I need some help.
I've got a segmented control. if segment 0 is clicked it shows a UIView, containing a uitableview.
If segment 2 is clicked it shows another UIView which contains a uitableview as well.
These two tableviews got the same datasource. But i want the second tableview to have an other datasource. SO i thougth of loading another nib into the second uiview containing a the tableview which gets its data from the corresponding .m file.
I don't know wheather this is the best solution. If you've got any other ideas let me know :)
thanks in advance!

I think the best way to do this is to have just one table view. In the cellForRow method have a conditional which queries the state of the segmented control. Depending on the result of that if statement, return the type of cell you want. In addition, in your segmented control callback you'll have to do a [tableView reloadData]

Do you know that you can have the same tableview display different data sets? You don' have to use an entirely different NIB just to change UITableViews so you can display different data. Or am I understanding your question incorrectly?

Related

Labels and images above TableView don't show up on device

So, I've laid out a UITableViewController with two prototype cells, and a view in the TableView's header area. In the header area, there are two views that each hold an icon and a label, Friends and Groups.
It looks all good in the Storyboard Editor, but when the screen actually loads, the images and labels in question are gone. I'm fairly new to iOS, so I haven't run into this before. Here are a couple screen shots to illustrate:
In the storyboard editor:
On the simulator:
Any thoughts? Thanks in advance for your help.
You've implemented the data source methods in your view controller, correct?
If not, UITableView will call a method that its data source implements: tableView:cellForRowAtIndexPath: from the UITableViewDataSource protocol, where you would return the cell to use, in this case the cell with the Identifier that you specified in your Storyboard.
We figured out that this was because the tableHeaderView of a UITableView is really weird about updating/redrawing. It's very difficult to get it to act in any sort of expected behavior.
Instead of using UIImageViews, we used UIButtons. The buttons seem to know how and when to updated and redraw themselves, so that worked.

Calling UITableView's cellForRowAtIndexPath: for just one iteration

When attempting to create a form with UITextFields, it appears that cellForRowAtIndexPath: gets called every time a user scrolls up and down the tableView. When this happens, a new UITextField is created, and the old UITextFields are no longer visible. Is there a way for the cellForRowAtIndexPath: method to be called for just one iteration?
Check the docs for UITableViewCell, especially A Closer Look at Table-View Cells and the section about static cell content.
Perhaps you might consider a simple UIScrollView rather than a UITableView? It's difficult to tell what you're trying to accomplish here. Perhaps add a bit more detail to your question.
Create UITableViewCell nibs in Interface Builder with UITextFields and link all of the objects with the viewController class.

how to use UITableViews for multiple datasets

I am currently playing around with a navigational based app. Where I want to allow the user to construct a search query by selecting one of several different uitableview cells when touched leads them to a sub uitableview where I will display the data for the user to select.
each cell will load the same subview however it will load it with different datasets. I am wanting to know an appropriate way of handling the transition of data (when the user selects the cell from the subveiw how can I control which cell that data should be sent back to?
I am thinking about passing the subview the Indexpath of the mainviews selected cell.. then passing it back to when the subview is poped from the stack so that it knows where the data needs to be.. is that the best solution? or is their another way of doing this?
Yes, give the subview a property for the indexPath of main view's selected cell. Set this property in the main view's didSelectCell method before pushing the subview.
Once you pass that indexPath back to the main view with you data, you can use
[self cellForRowAtIndexPath:indexPath]
to access the correct cell.

iPhone: can I add Tableview in cell of another tableview?

I have to create a UITableView. Suppose there are 2 table views TableView1 and TableView2. TableView2 will contain suppose 2 text boxes. And I have to add TableView2 in one cell of TableView1. Finally I have to access the values of text box from the inner TableView2 in the TableView1.
I am new to iPhone development. In short I have to add a tableview to the cell of another tableview. I don't know whether this is possible. If it is, would someone please provide me some link or code to do it.
This is not look good design. You can also use two text field in same cell and make it more in height also make a horizontal separator. also if you have only two textfields then make them global and declared as property.And add in a particular cell.
Read some tutorial for making custom cells and give some time to learning these tutorials.
See this link and by googling you can easily find more on this topic.
Yes, you can do. Of course, It is not good practice to do like this. Still you want then here is the trick to do that.
Create Two ViewController and inherit them using UITableviewController say ViewController1 and ViewController2.
Now in cell of Tableview1 add ViewController2 object. So Tableview2 would in Tableview1's cell. Now you need to handle inner tableview delegate & Datasource in Viewcontroller2. So you don't need to do lots of if.. else in same view controller.
Now you can take two textfield in Viewcontroller2.h file and assign cell's textField to that in cellForrowIndexPath method. So you can access both the textfield any time you want.
I know my answer is bit confusing but ask me any question if you have.

table view cells with different controls

I was working with the grouped table view , and i wanted different controls for every row i.e switch control for 1st,radio button for 2nd ,checkbox for 3rd and so on.. how can this be implemented programmatically that is without using interface builder
thanks in advance
CharlieMezak said is right, you need to create in UIControls directly in cellForRowAtIndexPath , and add as subviews to contentView of the cell
For reference see the link below
http://www.e-string.com/content/custom-uitableviewcells-interface-builder
the link specifies the code to create cells programmatically as well as using IB.
Table View Programming Guide for iOS
Read the programing guide, and remember to use different CellIdentifier for each type of cell.
This is a pretty vague question.
Obviously you need to provide the cells to the tableview in its cellForRowAtIndexPath delegate/datasource method. So, either in that method or during the initialization of your view controller, build the UITableViewCell instances that you need, adding the various controls that you want to them as subviews and connecting the controls to your view controller so you can detect when they have been changed. Then just return the appropriate cell in the cellForRowAtIndexPath method.
Personally, I think it's a lot easier to use IB in cases like this. Just create an IBOutlet instance variable for each custom cell you want, and return the right cell in cellForRowAtIndexPath.