<pre name="code" class="objc">- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
ColorCell *cell = (ColorCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *array = [[NSArray alloc] initWithObjects:@"系统默认色",@"自我本色", @"助运色",@"旺财色",@"旺桃花色",@"其他颜色",@"其他颜色",@"其他颜色",@"其他颜色",@"其他颜色",nil];
NSInteger row = indexPath.row;
if (cell==nil) {
cell = [[ColorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
cell.operationLabel.text = [array objectAtIndex:row];
cell.loginField.tag = row;
if(indexPath.row==currentIndex){
cell.accessoryType=UITableViewCellAccessoryCheckmark;
}
else{
cell.accessoryType=UITableViewCellAccessoryNone;
}
}
return cell;
}
#pragma mark - UITableView delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row==currentIndex){
return;
}
NSIndexPath *oldIndexPath = [NSIndexPath indexPathForRow:currentIndex inSection:0];
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
if (newCell.accessoryType == UITableViewCellAccessoryNone) {
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
newCell.selectionStyle = UITableViewCellSelectionStyleNone;
}
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:oldIndexPath];
if (oldCell.accessoryType == UITableViewCellAccessoryCheckmark) {
oldCell.accessoryType = UITableViewCellAccessoryNone;
}
currentIndex=indexPath.row;
}
单选按钮的实现
最新推荐文章于 2023-02-06 14:48:50 发布