2011-10-26 5 views
2

現在、ある行の右側にアイコンを追加して、その特定の行を選択すると点灯します。iOS - プログラムでTableRowの右側にToggleSwitchを追加する

-(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; 
} 

画像の代わりに、使用可能なトグルスイッチを描画するにはどうすればよいですか?

答えて

5

あなたがそれにサブビューを追加することができるようにプロパティaccessoryViewは、いつものUIViewのです:

UISwitch *toggleSwitch = [[UISwitch alloc] init]; 
cell.accessoryView = [[UIView alloc] initWithFrame:toggleSwitch.frame]; 
[cell.accessoryView addSubview:toggleSwitch]; 

P.S.割り当てられたオブジェクトを解放することを忘れないでください!

関連する問題