PDA

View Full Version : UISimpleTableViewCell and accessoryView




PeyloW
Mar 23, 2008, 08:31 AM
I have tried to add a UISwitch as an accessory view to one of the rows in my table.

My problem is that the accessory view is invisible. By initializing the UISwitch with the CGRectZero frame I can get the UISipleTableViewCell's text label to truncate, so something is there :). I have also tried to override acceroryRectForBounds:, but with no success.

If I use the inherited addSubview: from UIView the UISwitch do show up. But I do not think this is the right way to do it.

Has anyonw successfully used an accessory view with a UISimpleTableViewCell, or UITableViewCell?



cmaier
Mar 23, 2008, 09:47 AM
I have tried to add a UISwitch as an accessory view to one of the rows in my table.

My problem is that the accessory view is invisible. By initializing the UISwitch with the CGRectZero frame I can get the UISipleTableViewCell's text label to truncate, so something is there :). I have also tried to override acceroryRectForBounds:, but with no success.

If I use the inherited addSubview: from UIView the UISwitch do show up. But I do not think this is the right way to do it.

Has anyonw successfully used an accessory view with a UISimpleTableViewCell, or UITableViewCell?

Why not just use addSubview?

Anyway, I haven't tried this. Did you check in the debugger to see if loadView is getting clled on the UISwitch?

Matt342
Mar 23, 2008, 03:50 PM
Hi!

I'm having the same problem. I cannot get it to show. Can you post the code that you used to show the UISwitch?

~Matt

I have tried to add a UISwitch as an accessory view to one of the rows in my table.

My problem is that the accessory view is invisible. By initializing the UISwitch with the CGRectZero frame I can get the UISipleTableViewCell's text label to truncate, so something is there :). I have also tried to override acceroryRectForBounds:, but with no success.

If I use the inherited addSubview: from UIView the UISwitch do show up. But I do not think this is the right way to do it.

Has anyonw successfully used an accessory view with a UISimpleTableViewCell, or UITableViewCell?

PeyloW
Mar 24, 2008, 02:39 PM
Hi!

I'm having the same problem. I cannot get it to show. Can you post the code that you used to show the UISwitch?

~Matt
This is the method I use to create my table cells:

- (UITableViewCell *)tableViewCellWithLabel:(NSString *)label text:(NSString *)text
{
UISimpleTableViewCell *tableCell = [[[UISimpleTableViewCell alloc] initWithFrame:CGRectZero] autorelease];
tableCell.text = label;

UISwitch *aswitch = [[[UISwitch alloc] initWithFrame:CGRectMake(200, 7, 100, 30)] autorelease];
//[tableCell addSubview:aswitch]; // This one works!
tableCell.accessoryView = aswitch; // This one do not!

return tableCell;
}

gregjmclaughlin
Mar 28, 2008, 05:40 PM
This is the method I use to create my table cells:

- (UITableViewCell *)tableViewCellWithLabel:(NSString *)label text:(NSString *)text
{
UISimpleTableViewCell *tableCell = [[[UISimpleTableViewCell alloc] initWithFrame:CGRectZero] autorelease];
tableCell.text = label;

UISwitch *aswitch = [[[UISwitch alloc] initWithFrame:CGRectMake(200, 7, 100, 30)] autorelease];
//[tableCell addSubview:aswitch]; // This one works!
tableCell.accessoryView = aswitch; // This one do not!

return tableCell;
}


Try using both calls. In other words:

[tableCell addSubview:aswitch];
tableCell.accessoryView = aswitch;

as a work around. This works for me. You can also change your initWithFrame: to use CGRectZero as the above combination will make the default sized switch and position it correctly.

I don't know that it is intended that you need the addSubview ... but at least for now you seem to.

Hope that helps,

Greg