1. 在「tableView:cellForRowAtIndexPath:」裡加入
UISwitch *switchControl = [[UISwitch alloc] initWithFrame:CGRectMake(1.0, 1.0, 20.0, 30.0)];
switchControl.on = NO;
[switchControl addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = switchControl;
2. 再新增這個method
- (void) switchChanged:(id)sender {
UISwitch *switchControl = sender;
NSLog( @"The switch is %@", switchControl.on ? @"ON" : @"OFF" );
}
就完成了!!!
更詳細的請看蘋果官方文件
沒有留言:
張貼留言