2010-12-15 13 views
1

私のアプリケーションのナビゲーションベースとビューは、UITableviewControllerです。特定のUIViewtableセルのONとOFFのスイッチコントロールを追加する必要があります。追加する方法。テーブルビューのセルにスイッチを追加する方法

+0

可能重複してい-tableView:cellForRowAtIndexPath:方法(http://stackoverflow.com/questions/3770019/uiswitch-in-にスイッチを追加することができますa-uitableview-cell) – Mac

答えて

3

また、古典的なこの質問は既にここでたくさんお願いしています。たとえば、this questionを参照してください。より多くの結果を得るにはUITableViewUISwitchを検索してください。

+0

私の解答を得るサンプルありがとう – SOF

3

あなたは[のUITableViewのセルにUISwitch]のUITableViewDataSource Protocol

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell... 
    UISwitch *aSwitch = [[[UISwitch alloc] init] autorelease]; 
    [aSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; 
    [cell.contentView addSubview:aSwitch]; 
    return cell; 
} 
+0

スイッチコントローラを追加してくれてありがとうございます。 – SOF

関連する問題