UITableView删除添加,移动,分区,索引,自定义UITableViewCell
2015-10-22 10:33
561 查看
UITableView
// // ViewController.m // tabview // // Created by Young on 15/10/21. // Copyright © 2015年 Young. All rights reserved. // #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UITableView *tabview; @property NSDictionary*dic; @property NSArray* arr; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.dic=@{ @"西游记":@[ @"师傅", @"猴哥", @"呆子", @"沙老三" ] , @"三国":@[ @"诸葛亮", @"刘备", @"关羽", ], @"喜洋洋":@[ @"懒洋洋" ,@"村长", @"灰太狼",@"" ,@"红太狼" ,@"小灰灰" , @"一根草"], @"盗墓笔记":@[ @"三叔", @"闷油瓶", @"潘子" ,@"大奎" ,@"胖爷"], }; self.arr= [self.dic allKeys]; self.tabview.dataSource=self; self.tabview.delegate=self; [self.tabview setEditing:YES]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [_dic[ _arr[section] ] count]; } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell; if (indexPath.row%2==0) { cell= [tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath]; } else cell= [tableView dequeueReusableCellWithIdentifier:@"cell2" forIndexPath:indexPath]; cell.textLabel.text=[_dic[ _arr[indexPath.section] ] objectAtIndex:indexPath.row]; return cell; } -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row%2==0) { return UITableViewCellEditingStyleDelete; } return UITableViewCellEditingStyleInsert ; } -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ // if (indexPath.row%2==0) { // return YES; // } return YES; } -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ } -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{ } -(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{ return @"del"; } - (nullable NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return _arr; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return [_arr count]; } -(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return _arr[section]; } -(NSString*)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{ return [NSString stringWithFormat:@"共 %d 个人物。。" , [self tableView:tableView numberOfRowsInSection:section] ]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- 举例详解iOS开发过程中的沙盒机制与文件
- Android和IOS的浏览器中检测是否安装某个客户端的方法
- javascript实现阻止iOS APP中的链接打开Safari浏览器
- IOS开发第三方语音-微信语音
- 解析iOS开发中的FirstResponder第一响应对象