UITableView inside a Custom UITableViewCell - iphone

In my app I have a TableView that displays a list of Items. Tapping on any cell will expand it and will display information related to tapped item. I want to display the information in tabular form, will it be a good approach to have a UITableView inside a UITableViewCell?

Have a look to my answer in this post.
I think it is what you are looking for.

I am suggesting u to go for master-detail view controllers :) ,for your question "have a UITableView inside a UITableViewCell " for this u need to subclass the UITableviewCell and in that cell u put or add another tableview by managing datasource and delegate in custom cell see my answer it shows how to add tableview within the custom UITableView cell see hear and before that u hav to incerease the row height for each cell i did not included it, "one thing i created all programatically not used xib" :) hope u get some idea .

Related

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.

iPhone UITableViewCell with checkbox

I have a custom-subclassed UITableViewCell which will include a few labels, to which I want to add some checkbox functionality. One question label and five options are multi-selectable in that UITableviewCell subclass
Since I'm already in a cell, is it possible to use UITableViewCellAccessoryCheckmark to imitate checkbox functionality? Another option would be to navigate to another tableview using UINavigationController, but I want the user to see the options in the same page.
Also, since I don't know the number of options beforehand, is it possible to design this custom cell using a XIB and yet still dynamically add some items (for example UISwitch, or UIButtons) at runtime? Or do I have to code it all without using a XIB?
In short, Yes.
UITableViewCell is a subclass (somewhere down the way) of a UIView. That said you can insert a UITableView in it and create your checkbox allike cells. Think of it as nested tables:
Table of questions -> question cell -> table of answers -> answer cell.
So what you want to do is to make your custom UITableViewCell implement UITableViewDelegate and UITableViewDataSource then you want to insert an UITableView in the IB.
When you want to show your question cell with 4 answers you would pass a parameter of answers as a NSArray to the custom UITableViewCell. It then will use it to create inner cells that will behave as answer cells.
Hope that helps.

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.

Insert ScrollView in TableView?

I have a TableView with one cell and I want to insert in this cell a lot of text so I think I'll need to use a ScrollView for scroll the text.
How can I insert? Is correct this method?
This is a help in the application, is correct use this modality?
Sorry but I'm a beginner and I don't have an iPhone or iPod, thanks!
While I concur with 7KV7's original comment, it doesn't look like there is need of a tableview in this scenario...
Just in case someone else happens upon this looking for an answer to the "Scrollview in a Tableview" question here are few clarifying points for the above comments.
The technical problem with having a tableview and a scrollview together on the same view is that UITableView is already a descendent of UIScrollView and if you attempt to handle both in the same view then you will end up with quite a mess with conflicting delegate messages.
As suggested by iPhonePgr, you can create a custom UITableViewCell. The first thought would be to let the UITableViewCell act as the delegate for it's own scroll view. The problem here is that the cell and it's contents could be discarded or reused at any moment as part of tableview's dequeue functionality.
So some ground rules to guide your implementation:
Whatever your solution, you're probably going to end up making a custom controller class, possibly derived from NSObject and implementing UIScrollViewDelegate.
The custom controller object acts as the mediator between the model object and the cell.
You will probably have an array or array-of-arrays that mirrors the model hierarchy driving the UITableView structure.
Because the cells can be discarded at any time you will have restore the scroll view state on cell initialization and preserve the state has part of handling your delegate actions or through a custom UITableViewCell implementing prepareForReuse.
Hopefully these points will come in useful to anyone who runs across this entry.
You need to create a custom cell by inheriting UITableViewCell and then add UIScrollView in the customcell. Then Use that cell in the Table view.
you can put your text in UITextView and add it as a subview in your UITableViewCell,because
UITextView is inherited from UIScrollView,
No need to add UIScrollView if you use UITextView
When you create UITableView you implement a number of delegate method which you can see by pressing the window key and then double clicking the UITableView delegate . In one of the methods you can set the cell height as per your requirement. By doing this your cell height can vary.
- (CGFloat)tableView:(UITableView *)resultTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 150;
}
As your table has a defined height, when the text in cell will be too much to contain into a scrollview will be automatically inserted.

how can you create a login screen like the iPhone facebook app?

The Facebook app for the iPhone has a great username/password setup where it almost looks like it is a uitableview with UITextField's inside the two rows, is this how it is done? Or would it be something different to this altogether?
If it is a tableview, how can I access the textfields inside the tableview once the user hits the Login button? Is there a quick way to iterate over the cells in a tableview?
A simple one, I know, but I didnt want to implement an elaborate tableview if I didnt need to...
The source: https://github.com/c99koder/lastfm-iphone
Edited: It's possible you customize the UITableViewCell and put a UITextField inside. However, there is an even easy way to achieve this, since the login / signup page would almost always be static. See below.
LastFM for iPhone used a similar login / signup page design. And they open-sourced their code. Take a look at the nib file and you will know how LastFM did this. :-)
Screenshot 1: original
Screenshot 2: after I removed some of the background png files.
Create a tableview controller and go to the xib file -> attributes inspector->tableview and select "group styled" instead of plain. Then u can customize the tableview cells in the code by adding the textfields for username and password. Then create a new UIView and set the view to the tableview's footer view for the login button.
For more explanation regarding the same, go through the answer for this question.
Table view in iPhone in grouped style
It looks like it's not using a UITableView at all (otherwise, you'd be able to scroll the page up and down). It's just two UITextFields over custom backgrounds (or with custom backgrounds).
Now, if you wanted to use a UITableView, what you could do is store as variables the UITextFields within the UITableViewCells. Then, when the person clicks a login button, you just get the text value from the UITextFields.
But, again, if you wanted to emulate the Facebook look, you don't need to bother with the UITableView.
Hope this helps!
Alright, now that I understand your question (thanks #Jonathan!), yes it does look like it is a tableview using custom UITableViewCells with a UITextField.
After creating the custom cell with a UITextField you can assign your view controller as the UITextField delegate and access the values at various points through the delegate methods:
– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:
As an example, in your textFieldShouldReturn:, you can grab a reference to the indexPath of that cell with :
NSIndexPath *indexPath = [self.loginTable indexPathForCell:(MemberLoginCell*)[[textField superview] superview]];
And then to the cell with:
MemberLoginCell *cell = (MemberLoginCell*)[self.loginTable cellForRowAtIndexPath:indexPath];
Or simply grab the textField.text value and assign it to an NSString that can be passed to your LOGIN method as required.
I know there's already an accepted answer, but I created a facebook-type login page, using a UITableView. The code is here on github