Edit mode for UITableViewCell using Interface Builder - iphone

I converted my old UITableViewCell from being programmatically created to using Interface Builder and a Xib. When implemented in code and in edit mode, I moved some of the labels in the cell to make room for the delete button. How do I change the layout of the cell in edit mode when implemented as a Xib? Preferably animated. Links or tutorials are certainly welcome!
If it matters, this is for a 3.0 SDK app.

You need to get a reference to the subviews you would like to move. Two ways to do this are:
Tag the views in IB
Use IBOutlets
If you tag the subview you would like to move, you can find it by:
[cell.contentView viewWithTag:kMyTag];
If you choose to use IBOutlets, you should consider creating Cell Controllers for each cell.
A good tutorial on this can be found here:
http://bill.dudney.net/roller/objc/entry/uitableview_from_a_nib_file
Also consider moving your cell logic into the cell controllers and out of the table view controller as mentioned in this tutorial:
http://cocoawithlove.com/2008/12/heterogeneous-cells-in.html

Related

Multiple images on a custom table view cell (Swift)

I'm trying to think of how to best solve this...currently my app supports a user uploading and saving an image to Parse and then retrieving it to a UIImageView on a custom table view cell. However, how would I go about implementing multiple pictures where a user swipes the top picture and the next photo is shown, all in the same table cell? Does this require a new view? If so, how do I do this?
Thanks!
Follow that tutorial that Caleb recommended but you could also use a gesture recognizer on your custom cell. You can design the cell in the storyboard, make a subclass from UITableViewCell and connect the components via outlets to your custom class.

iPhone- how to use Storyboard with custom UITableView cells and CellWithIdentifier

I'm trying to make use of the new Storyboard designer and the ease of drawing UITableView cells instead of programmatically "designing" each row.
A good example of a standard cell is linked here at stack overflow:
iPhone - dequeueReusableCellWithIdentifier usage
Instead of the linked approach of using "[cell textLabel]" I want to use my own labels, buttons and images on top of each row.
Therefore I created several prototype cells/rows and assigned identifiers to them (using Storyboard).
Now: what is the smartest way of accessing each row's "custom" controls/labels? I tried searching for accessing them by ID, but didn't find anything.
My thinking was it should work along this lines:
[[[cell subviews] getObjectByID:#"labelTime"] setText:#"Whatever"];
Is my expectation of the APIs completely wrong or didn't I just find the right API, yet?
Any ideas or recommendations?
For each new custom UITableViewCell that you create in storyboard, you will want to create a new class file which implements UITableViewCell to link it to. Be sure to map all of the controls within your new cell that you laid out in storyboard to instance properties. Then you'll just use it with dequeuing like normal:
YourTableViewCellClass *cell = (YourTableViewCellClass*)[tableView dequeueReusableCellWithIdentifier:#"YourCellIdentifierStringDefinedInStoryBoard"];
// then set the properties for the class.
cell.labelTime = #"whatever";
There are two ways you can get to your custom subviews. The simpler way is using tags. Every view has a tag property which is an integer. You can set the tag in the nib, and set or get it in code. You can search a view tree for a view with a given tag by sending viewWithTag: to the root of the tree. So, for example, you could give your labelTime view the tag 57, and in your code, you'd find the view like this:
UILabel *label = (UILabel *)[cell viewWithTag:57];
The downside of using tags is that you have to keep the tag numbers in sync between your nib and your code. If they get out of sync, you'll either get the wrong view back or you'll get nil (and since you can send messages to nil, the system won't give you an error when that happens). Still, tags are so convenient that it's pretty common to use them like this.
The other way is to create a custom subclass of UITableViewCell with an IBOutlet property for each custom subview. You can hook up the outlets to the subviews in the nib, and access the subviews via the properties in your code:
MyTableViewCell *myCell = (MyTableViewCell *)cell;
UILabel *label = cell.labelTime;
This entails writing a lot more boilerplate than using tags, but it has the advantage that you will get warnings or errors (either at compile-time or when you first try to load the nib) if your nib and your code get out of sync.
Don't be a doofus like I was being. :)
Make sure you set the Identifier value in the Attributes Inspector of the custom cell. Setting the Restoration ID of the custom cell in the Identity Inspector is the wrong way to go, and that's exactly what I did. Major facepalm for myself.
For more implementation details of how to do it, using the methods described by mservidio and rob, check out the section "Designing Our own Prototype Cells" in this tutorial.

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.

how do i fully customize a tableview

i want to customize my tableview, like the tipulator app for the iphone.
And heres my app:
Each UITableViewCell has a few subviews which you can replace with your own. They are:
UITableViewCell.imageView
UITableViewCell.contentView
UITableViewCell.backgroundView
UITableViewCell.accessoryView
As Gendolkari pointed out, Cocoa With Love has a great guide on custom UITableViews.
The theory is that you replace each of those views with an appropriate view to "skin" your UITableViewCells.
When replacing the background view, you check for the first and last cells when skinning the background view, otherwise you can use a "middle" background image. Implement it as a UIImageView. As far as the other views, use what you want.
Additionally, you can use a completely custom NIB file and load that in instead of the default styles provided by UIKit.
While the others are right in suggesting ways to subclass UITableView or its components, this screenshot doesn't look like it's showing a UITableView.
My guess is that they're just drawing custom images onto a background and checking certain areas for taps. What you should do is read up on the drawing methods as well as on intercepting taps and touches.
Here's a really good guide on custom styling for your table:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
Create your own UITableViewCell, and use it, rather than a "generic" one.
You can do this directly in XCode with "File->New File" Then in "Cocoa Touch Class", choose "Objective-C Class" - and under the "Subclass" popup, select "UITableViewCell".
It well generate a XIB, which you can use in IB to customize the look.
Instantiate and pass-in there cells in your UITableView code, instead of the normal UITableViewCells.

iPhone app - some custom UITableViewCell questions

At the moment, I have a settings view in my iPhone app built with Interface builder, it consists of a background image, some text fields, labels and buttons. Because this looks bad, I want to convert the settings view to an UITableView with custom UITableViewCells.
I already tried adding some cells into my settings view's XIB and returning them in the cellForRowAtIndexPath method (with [return myCell];), as written in Apple's tutorial, but this was not working for me - my whole TableView looked strange and it only showed the first cell correctly.
Is it possible to design these custom cells in Interface Builder? Do I have to create an empty XIB for them or can I put them in my view's XIB? And how do I insert them into my TableView?
Thanks in advance,
Yassin
You can absolutely add custom table cells that you built in interface builder. This includes both static cells and Dynamic cells. However without you providing more information the best I can say is "double check the docs and try again." I can only say that it works and it's rather straightforward so it's hard to say what you may have missed. It might be more helpful if you post what you have for the tableView:cellForRowAtIndexPath method.
Since you say you just have some text fields, I would recommend looking at the technique for static row content section of the Table View Programming guide. You probably would want to have each field of your form correspond to a row in a Segmented Table View, it'll make everything look nicer.