2013年3月7日 星期四

將TableViewCell的accessoryView換成Switch Button

在這- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

加入
if (indexPath.section == 1 && indexPath.row == 1) {
cell.textLabel.text = @"I Have A Switch";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
cell.accessoryView = switchView;
[switchView setOn:NO animated:NO];
[switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
[switchView release];
}

沒有留言:

張貼留言