单选按钮的实现

来源:互联网 发布:2017编程语言趋势 编辑:程序博客网 时间:2024/05/17 04:45
<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;        }


                                             
0 0