IOS开发之tableview只选中一行
来源:未知 责任编辑:责任编辑 发表时间:2014-01-25 11:34 点击:次
场景:一个弹出层,包含一个Tableview,每一行为一个选择条件,且只能选择一个。选中后文体有颜色变化,后面还会有对勾。选择另一个后,前一个恢复成普通状态。
示例代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { int newRow = [indexPath row]; int oldRow = [lastIndexPath row]; if (newRow != oldRow) { UITableViewCell *newCell = [tableView cellForRowAtIndexPath: indexPath]; newCell.accessoryType = UITableViewCellAccessoryCheckmark; UITableViewCell *oldCell = [tableView cellForRowAtIndexPath: lastIndexPath]; oldCell.accessoryType = UITableViewCellAccessoryNone; lastIndexPath = indexPath; } [tableView deselectRowAtIndexPath:indexPath animated:YES]; }注意: lastIndexPath为私有变量,页面第一次加载为nil,需追加判断。
相关新闻>>
- 发表评论
-
- 最新评论 更多>>
今日头条
更多>>您可能感兴趣的文章
- 多线程之NSInvocationOperation
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- iphone开发之object c基础一定义接口
- (iPhone/iPad开发)presentViewController相应方法在SDK5.0前后
- Lexical or Preprocessor Issue 'xxx.h
- Android:实现TabWidget选项卡按钮在屏幕下方
- iPhone开发学习笔记006—— NSNotification自定义通知名
- ios开发问题:添加库和复制其它工程文件编译错误问题
- iPhone应用开发之十一:常用的三种动画表现效果
- Memory on the iPhone