@protocol SwitchCellDelegate
// スイッチの切換えを通知する
-(void) tableView:(UITableView*)tableView changeSwitchValue:(BOOL)on indexPath:(NSIndexPath*)indexPath;
@end
@interface SwitchCell : UITableViewCell
{
id _delegate;
}
@property (nonatomic, assign) id<SwitchCellDelegate> Delegate;
@property (nonatomic, retain) IBOutlet UISwitch* ValueSwitch;
@property (nonatomic, retain) IBOutlet UILabel* Title;
// スイッチの値が変更されたときのコールバック
-(IBAction) changeSwithValue:(id)sender;
@end
// スイッチの値が変更されたときのコールバック
-(IBAction) changeSwithValue:(id)sender
{
// スーパークラスをたどり、このセルを保持するテーブルビューを探す
id tableView = [sender superview];
while ([tableView isKindOfClass:[UITableView class]] == NO) {
tableView = [tableView superview];
}
// NSIndexPathを得る
NSIndexPath* indexPath = [((UITableView*)tableView) indexPathForCell:self];
// デリゲートメソッドをコールする
[_delegate tableView:tableView changeSwitchValue:self.ValueSwitch.on indexPath:indexPath];
}
@interface SCR_MNU_005_SettingIndex : UITableViewController
<SwitchCellDelegate>
{
...
}
cell.Delegate = self;
-(void) tableView:(UITableView *)tableView changeSwitchValue:(BOOL)on indexPath:(NSIndexPath *)indexPath
{
CategoryInfo* category = [_categoryList objectAtIndex:indexPath.section];
CellInfo* cellInfo = [category.CellList objectAtIndex:indexPath.row];
NSLog(@"ログ表示: [%@]", on?@"ON":@"OFF");
}
コメント