thndrkiss
thndrkiss

Reputation: 4595

how to add a label and button in the same line in a tableview

I am using UICatalog example and trying to find whether it is possible to add a label next to a button. Please let me know how to approach this problem

Upvotes: 1

Views: 318

Answers (1)

RedBlueThing
RedBlueThing

Reputation: 42522

There are a couple of ways to do this, but I tend to create a UITableViewCell derivative with an associated XIB file. Modify the XIB in Interface Builder to include the button and the label. Hook those objects up to IBOutlets and IBActions in your UITableViewCell class.

When you implement your cellForRowAtIndexPath you can grab the top level object from your UITableViewCell XIB file like this:

NSArray * topLevelObjects = [[NSBundle mainBudnle] loadNibNamed:@"YourCellNib" owner:self options:nil];
cell = [topLevelOjects objectAtIndex:0];

You can then cast your cell object to your UITableViewCell class:

YourCellClass * thingCell = (YourCellClass*)cell;

You can then use the YourCellClass to control (and receive events from) the cell in the UITableView.

Upvotes: 1

Related Questions