下面我们来看一下自定义辅助视图:我们会经常看到这样的cell
需要用到accessoryview实现
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reuseIdentifier"];
}
if (indexPath.row == 1) {
UISwitch *mySwitch = [[UISwitch alloc]init];
mySwitch.on = NO;
[mySwitch addTarget:self action:@selector(switchOnOrOff:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = mySwitch;
}
else {
cell.accessoryView = nil;
}
return cell;
}