UITableViewCell 单选
来源:互联网 发布:js验证手机号码 编辑:程序博客网 时间:2024/06/07 01:19
1.定义属性
@property (nonatomic, assign) int rowIndex;
2.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];// 当前cell
if (_rowIndex == indexPath.row)
{
if (cell.accessoryType == UITableViewCellAccessoryNone)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
else
{
// 取消前一个选中的,就是单选啦
NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:_rowIndex inSection:0];
UITableViewCell *lastCell = [tableView cellForRowAtIndexPath:lastIndex];
lastCell.accessoryType = UITableViewCellAccessoryNone;
// 修改选中的cell未选择
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
// 保存选中的
_rowIndex = indexPath.row;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@property (nonatomic, assign) int rowIndex;
2.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];// 当前cell
if (_rowIndex == indexPath.row)
{
if (cell.accessoryType == UITableViewCellAccessoryNone)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
else
{
// 取消前一个选中的,就是单选啦
NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:_rowIndex inSection:0];
UITableViewCell *lastCell = [tableView cellForRowAtIndexPath:lastIndex];
lastCell.accessoryType = UITableViewCellAccessoryNone;
// 修改选中的cell未选择
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
// 保存选中的
_rowIndex = indexPath.row;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
0 0
- UITableViewCell 单选
- UITableViewCell(单选、多选)
- UITableViewCell 中的单选控制
- iOS UITableViewCell的单选
- UITableViewCell 中的单选控制 UITableViewCellAccessoryCheckmark
- UITableViewCell 中的单选控制 UITableViewCellAccessoryCheckmark
- UITableViewCell 中的单选控制 UITableViewCellAccessoryCheckmark
- UITableViewCell
- UITableViewCell
- UITableViewCell
- UITableViewCell
- UITableViewCell
- UITableViewCell
- UITableViewCell
- uitableviewcell
- UITableviewcell
- UITableViewCell
- UITableViewCell
- Swift 泛型(十九)
- 使用 Eclipse Memory Analyzer 检测内存泄漏问题
- Fedora 19: How to resize/extend (LVM) partition?
- 习题2-6 排列
- 【转载】FW:TCP半连接和syn攻击
- UITableViewCell 单选
- 字符串移位包含问题
- 套接字中的setsockopt接口功能
- 多线程下获取缓存问题
- NYOJ844A+BProblem(v)
- C 函数 strstr 的高效实现
- ant怎么用
- WebBrowser页面与WinForm交互技巧
- Openfire源码编译