Can I create UITableView with sub-cells? - iphone

Hi I want to create a table view with sub cells. What I mean by "sub cells" is, when I click a arrow pointer in a cell, it should show its sub cells with cell indentation.
Is this kind of cells available in iPhone?
If not, Is this possible to do it in some other way?

This isn't a standard capability of UITableView, but actually isn't that hard to implement. What you need to do is:
Create a custom UITableViewCell (perhaps called 'OutlineTableViewCell'). It should have a disclosure indicator
Create a class which implements the UITableViewDataSource protocol to manage the tree structure of the rows. It should manage the indent level and disclosure state.
Implement methods to expand/collapse sections of the tree (triggered by tapping the disclosure indicator)
Finally, subclass both of these to add the storage and display of your own data in the view

Not sure if that'll work in your case, but in one of my apps, I used the following work around to create a two-level table view with normal (level 1) items toggling (level 2) "sub"-cells:
I have a standard table view, and use its sections as level 1 items.
For each section, I use a custom view with a UIButton to act as the toggle.
I keep track of which sections are toggled on / off through an array, and simply return 0 elements for the section when it's off.
Sub-cells are just regular cells.

Related

Is it possible to do that with vertical scroll collection view or table view ?

Can somebody give advice about this ? I prefer the vertical scrolling.
Since it's android and I can't really post entire code, you can probably look at this link for help -
http://sdroid.blogspot.com.au/2011/01/fixed-header-in-tablelayout.html
I would suggest going for table view since collection view is generally for grid layouts. Since your layout looks more like a list of items stacked in one column, table view will be ideal and a little simpler. If you want more complex layout Collection view is much better.
According to apple docs -
A table view displays a list of items in a single column. UITableView
is a subclass of UIScrollView, which allows users to scroll through
the table, although UITableView allows vertical scrolling only. The
cells comprising the individual items of the table are UITableViewCell
objects; UITableView uses these objects to draw the visible rows of
the table. Cells have content—titles and images—and can have, near the
right edge, accessory views. Standard accessory views are disclosure
indicators or detail disclosure buttons; the former leads to the next
level in a data hierarchy and the latter leads to a detailed view of a
selected item. Accessory views can also be framework controls, such as
switches and sliders, or can be custom views. Table views can enter an
editing mode where users can insert, delete, and reorder rows of the
table.

Newbie TableView challenges

I am building an app that requires a tableview control so that users can select multiple rows and act upon them in some way. I find it easy to load my data and display it using the UITableViewController but it seems when I do it this way I am unable to place any other controls on the page, such as a toolbar to give the user some actions to perform on the selected rows. I can place a toolbar control on the form in the storyboard, but it doesn't render in the emulator.
Using a UIViewController and placing a TableView on it seems to come with its own set of confusing challenges (that will make total sense once I conquer them).
Is there any advice for a smooth way of getting a table view with toolbar controls? Thanks!
don't use a TableViewController. Use a Standard ViewController, then add a UITableView to it, and adjust the size. This way you will be able to do whatever else you want on that view without limiting yourself to the tableView only functionality.
When you do this make sure you add the datasource and delegate to the connected table. Then add cellForRowAtIndex, number of sections, number of rows, and whatever other delegate methods you need for your table.
Good luck
Is there any advice for a smooth way of getting a table view with toolbar controls?
Yes there are few ways to accomplish this, one way would be adding a footerview to your tableviewcontroller check these
http://developer.apple.com/
UIButtons on tableFooterView not responding to events
Easier way to add this is using storyboard.
Just drag and drop a view in to your tableviewcontroller, then you can adjust the views size and put anything from objects menu to inside of the view.
Now the problem with that is view will not be stable position at the bottom of the page like a tabbar. Lets say you have only 1 row in your tableview, footer view will go up just below that 1 row, lets say you have hundreds of items in your tableview toolbar will be at the bottom of the rows.
The other solutions for your problem would be either create a custom view and adding it to current view or window (this is little bit adbance),but if you want this just google it.
Or just as you said, create a viewcontroller and put a uitableview inside. Dont forget to add <UITableViewDelegate,UITableViewDataSource> to your .h file and then you can call UItableview delegate methods.\
Good Luck.

buttons in a table header to load tdifferent table views

What's the best way for me to add 2 custom buttons in the header of my UITableView?
On clicking either of those buttons, a different table View is loaded.
Thanks for the help!
Add the two buttons to the header, and use the IBActions of those buttons each to set the datasource to an other array. After that, use [tableView reloadData];
If you want to use buttons above the table, I'd suggest either using sections if your having no sections in your original table, or placing a toolbar above your table.
UISegmentedControl is pretty much for this purpose, then you can hook the events and switch the views accordingly... It looks better tan two separate buttons, and also better from the user experience perspective...
Second choice is to have two different tables or one table with two different data. I would prefer two tables, each having its own data, and delegates. Easier to write cell rendering code and all...
If both data are of the same type like "Array of MyObject", then you can come away with just a flag and some ( flag ? firstDataArray : secondDataArray) type of selections in the table delegate methods.
First add two different customs button and then add two different table Views bellow that custom buttons.
Use a separate UView and add both UIButton as subview into.
Then add this button's view in the parent view of your UITableView
Then both the button's view and UITableView will be the sibling view....

Rearranging rows in uitableview

I've an application in which each row contains an uiimageview and an uibutton. I have created them using custom cells, uitableviewcells. The button is to trigger the method, uiimagepickercontroller to pick an image from the library and show it in the imageview. I need that any user who uses the application can rearrange the rows as they wish so that they decide the order of the photos. code here
Reordering of rows in a tableview is pretty straightforward, you just need to implement a few methods of the UITableViewDataSource Protocol and your good to go. Have a look at the Table View Programming Guide for info & code.
http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/ManageReorderRow/ManageReorderRow.html
You could show an Edit button in the navigation bar if your using a navigation controller, which switches the table view to edit mode, causing the reordering control to be shown. This edit button could be changed to done, once the table is in edit mode of course. Don't forget to set the showsReorderControl property of the cell to YES. From then on, it's just a matter of implementing the right methods.

Multiple images per row in UITableView's cell

Is there any sample code that would illustrate how to have multiple images within each row?
Typical apps show a thumbnail to the left side with text to the right. I'd like to do that plus an image to the right of the text.
How would I go about doing this?
In interface builder, simply create a tableview cell that looks like you want. Then create a UITableViewCell subclass that has properties pointing to the elements of the new cell. Set the class of cell to the subclass then add cells of that class to the table in the standard way.
A tableview cell is just a view and you modify it and use it just like any other view.
You'll have to create a custom UITableView cell. Here's an example of using multiple UILabels in one. Here's another.
Pretty easy - follow Apple's documentation to create exactly the cell you want in Interface Builder with as many UIImage or whatever else you like. Look at Table View Programming Guide for details on how to make and load the custom cells - just be careful about performance when you put a lot of visual elements in a table view.