UISwitch 初始化
1.UISwitch的初始化
UISwitch *switchView = [[uiswitch alloc] initWithFrame:CGRectMake(54.0f, 16.0f, 100.0f, 28.0f)];
2.设置UISwitch的初始化状态
switchView.on = YES;//设置初始为ON的一边
3.UISwitch事件的响应
[switchview addtarget:self action:@selector(switchaction:) forcontrolevents:uicontroleventvaluechanged];
在cell中添加uiswitch
-
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = ; if (cell == nil) { cell = initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } if(==0){ cell.textLabel.text=@"新消息通知"; }else if(==1){ cell.textLabel.text=@"成员可邀请"; }else if(==2){ cell.textLabel.text=@"是否公开"; }
UISwitch *switchview = initWithFrame:CGRectZero]; switchview.tag = ; ; cell.accessoryView = switchview; ; return cell;
}