Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

PeyloW

macrumors newbie
Original poster
Mar 23, 2008
3
0
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

Suspended
Jul 25, 2007
25,405
33,474
California
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

macrumors regular
Jul 20, 2007
140
0
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

macrumors newbie
Original poster
Mar 23, 2008
3
0
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

macrumors newbie
Mar 28, 2008
1
0
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.