【发布时间】:2011-07-05 14:14:32
【问题描述】:
所以我有一个 UITableView,它的所有单元格都使用 UITableViewCellStyleValue1 呈现。
这种风格在 cell.indentationLevel
中非常适合我现在我需要在单元格中显示一个 UISwitch 而不是 detailTextLabel。我开始在 cellForRowAtIndexPath 工作,这是我的代码。
UISwitch *switchField = [[UISwitch alloc] init];
switchField.frame = CGRectMake(tableView.bounds.size.width - 194, 8, 94, 27);
switchField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
switchField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
[cell.contentView addSubview:switchField];
一开始效果很好,但每当我旋转设备时,Switch 的边界都保持不变。我认为通过向 cell.contentView 添加一个 UIView 可以在需要时进行对齐。
我错过了什么,最重要的是我应该做什么来实现我想要的?
谢谢。
【问题讨论】:
标签: iphone objective-c ios ipad xcode4