IOS开发 阅读器类APP可用开源框架介绍_第1页
IOS开发 阅读器类APP可用开源框架介绍_第2页
IOS开发 阅读器类APP可用开源框架介绍_第3页
IOS开发 阅读器类APP可用开源框架介绍_第4页
IOS开发 阅读器类APP可用开源框架介绍_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、继续介绍一个有用的TableView中全选单元格的例子,里面的方法可以用在阅读器中用 户对阅读内容来源的选择上,如图所示:运营高令全选运营高宇取消核心代码如下:objc view plaincopy1.2.3.4.5.6.-(void)viewDidLoadsuper viewDidLoad;/创建表视图_table_table = UITableView allocinitWithFrame:CGRectMake(0, 64, 320, 500) s tyle:UITableViewStylePlain;7.8.9.10._table.delegate = self;_table.dataS

2、ource = self;self .view addSubview:_table;11.12.13.14./将字典NO- checked装入可变数组中,来控制单元格左边对勾视图 _contacts = NSMutableArray array;for (int i = 0; i 10; i+) NSMutableDictionary *dic = NSMutableDictionary dictionary;15.16.17.18.19.20.21.22.23.24.25.1.2.3.4.5.6.dic setValue:NO forKey:checked;_contacts addObje

3、ct:dic;/创建屏幕左上方的全选按钮_button = UIButton buttonWithType:UIButtonTypeRoundedRect;_button setTitle :全选forState:UIControlStateNormal;_button.frame = CGRectMake(10, 10, 100, 50);_button addTarget:self action:selector(allSelect:) forControlEvents:UIControlEventTouchUpInside;self.view addSubview:_button; ob

4、jc view plaincopy/全选按钮的触发事件-(void)allSelect:(UIButton*)sender将表视图的所有的单元格放在数组里NSArray *anArrayOfIndexPath = NSArray arrayWithArray:_table indexPathsForVisibleRows;7.8.9.10.11.12.13.14.15.16.17.)18.19.20.21.22.23.24.25.26./27.ifh:indexPath;for (int i = 0; i anArrayOfIndexPath count; i+) /得到表视图的indexPa

5、thNSIndexPath *indexPath= anArrayOfIndexPath objectAtIndex:i;/创建每个单元格,LTableViewCell *cell = (LTableViewCell*)_table cellForRowAtIndexPatNSUInteger row = indexPath row;NSMutableDictionary *dic = _contacts objectAtIndex:row;/判断当前按钮的状态是全选还是取消,设置不同的标记if (UIButton*)sender titleLabel text isEqualToString

6、:全选dic setObject:伊YES forKey:checked;cell setChecked:YES;else dic setObject:伊NO forKey:checked;cell setChecked:NO;两种状态的切换(UIButton*)sender titleLabel text isEqualToString:全选)28.29.30.31.32.33.34.35.36.37.38.39.40.41.for (NSDictionary *dic in _contacts) dic setValue:YES forKey:checked; (UIButton*)sen

7、der setTitle:取消 forState:UIControlStateNormal;elsefor (NSDictionary *dic in _contacts) dic setValue:NO forKey:checked;(UIButton*)sender setTitle:全选forState:UIControlStateNormal; objc view plaincopy1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.-(UITableViewCell *)tableView:(UITableView *)t

8、ableView cellForRowAtIndexPat h:(NSIndexPath *)indexPathstatic NSString * identifier = Cell;/创建单元格LTableViewCell * cell = tableView dequeueReusableCellWithIdentifier:ide ntifier;if (cell = nil) cell = LTableViewCell allocinitWithStyle:UITableViewCellStyleDefa ult reuseIdentifier:identifier;NSUIntege

9、r row = indexPath row;NSMutableDictionary *dic = _contacts objectAtIndex:row;if (dic objectForKey:伊checked isEqualToString:NO) dic setObject:NO forKey:checked;cell setChecked:NO;else dic setObject:YES forKey:checked;cell setChecked:YES;return cell;23.objc view plaincopy1.2.3.4.5.-(void)tableView:(UI

10、TableView *)tableView didSelectRowAtIndexPath:(NSIndexP ath *)indexPathtableView deselectRowAtIndexPath:indexPath animated:YES;LTableViewCell *cell = (LTableViewCell*)tableView cellForRowAtIndexPath6.7.8.9.10.11.12.13.14.15.16.17.18.19.:indexPath;NSUInteger row = indexPath row;NSMutableDictionary *d

11、ic = _contacts objectAtIndex:row;/创建单元格左边的打钩视图if (dic objectForKey:伊checked isEqualToString:NO) dic setObject:YES forKey:checked;cell setChecked:YES;else dic setObject:NO forKey:checked;cell setChecked:NO;在 LTableViewCell 中objc view plaincopy1.2.3.4.5.6.7.8.5.09.10.11./用checked来判断是否加上对勾视图-(void)setChecked:(BOOL)checkedif (checked)m_checkImageView.image = UIImage imageNamed:Selected.png;self.backgroundView.backgroundColor = UIColor colorWithRed:223.0/25 green:230.0/255.0 blue:250.0/255.0 alpha:1.0;else12.13.14.15.16.17.18.

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论