Re: Design for custom tableviewcell button action
Re: Design for custom tableviewcell button action
- Subject: Re: Design for custom tableviewcell button action
- From: WT <email@hidden>
- Date: Thu, 25 Jun 2009 12:20:29 +0200
On Jun 25, 2009, at 11:46 AM, Alexander Spohr wrote:
Am 25.06.2009 um 10:54 schrieb WT:
On Jun 25, 2009, at 10:26 AM, Alexander Spohr wrote:
Why didn’t you put the cell into the controllers nib?
Make an outlet in your controller to reach the cell and just
return it when you need it?
Because -tableView:cellForRowAtIndexPath: needs to return a
different cell object for each visible row. Your code above returns
always the same object, the one table view cell archived in the
nib, which means that changing the data in one cell would change
the data in all visible cells, and all visible cells would have the
same data all the time.
Of course, you are right. I forgot that the OP wanted something like
an accessory which needs to be repetitive.
atze
Even with a custom cell with no extra controls, you'd need to return a
different cell object for each visible row. Try this and see what
happens:
- (NSInteger) tableView: (UITableView*) table_view
numberOfRowsInSection: (NSInteger) section
{
return 10;
}
- (UITableViewCell*) tableView: (UITableView*) table_view
cellForRowAtIndexPath: (NSIndexPath*) index_path
{
NSInteger row = [index_path row];
static NSString* cellID = @"cellID";
UITableViewCell* cell = nil;
cell = [table_view dequeueReusableCellWithIdentifier: cellID];
if (cell == nil)
{
cell = customCell;
}
if (row % 2 == 0)
{
cell.contentView.backgroundColor = [UIColor blueColor];
}
else
{
cell.contentView.backgroundColor = [UIColor redColor];
}
return cell;
}
You will NOT see a table with alternating colors for its cells. I had
thought that you'd see all cells with the same color, but in fact I
was wrong about that. What you do see is that only ONE cell has its
background colored. And it makes perfect sense, since cells are views
and the ONE custom cell is repeatedly added as a subview to the table
view "content" area for each row, but only the last one "sticks"
because, again, you only have one cell object.
Wagner_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden