Lou*_*ley 2 iphone uitableview ios
目前我正在向一行的右侧添加一个图标,并在选择该特定行时切换灯光.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
...
...
NSUInteger row = [indexPath row];
if(row == 3)
{
//Draw bulb in row
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bulb-on.png"]];
//Instead of image, draw toggle-switch here
}
else
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能绘制一个可用的切换开关而不是那个图像呢?
属性accessoryView只是一个普通的UIView,所以你可以添加任何子视图:
UISwitch *toggleSwitch = [[UISwitch alloc] init];
cell.accessoryView = [[UIView alloc] initWithFrame:toggleSwitch.frame];
[cell.accessoryView addSubview:toggleSwitch];
Run Code Online (Sandbox Code Playgroud)
PS别忘了释放分配的对象!
| 归档时间: |
|
| 查看次数: |
3844 次 |
| 最近记录: |