UI 15 UITableViewController & 系统自带快捷菜单 & 系统下拉刷新
2015-08-29 14:55
489 查看
UITableViewController 已经签订好tableView的两个协议,可以直接使用.
只要将必须完成的两个协议的内容写好即可.
下面的代码加入了系统默认的下拉刷新功能, 每次向下拉刷新时都添加一个@”哈哈”
代码实现如下:
这是创建文件时就已经写好的协议方法
当然, 协议中还有其他方法,比如, 有一个系统自带的快捷菜单
只要将必须完成的两个协议的内容写好即可.
下面的代码加入了系统默认的下拉刷新功能, 每次向下拉刷新时都添加一个@”哈哈”
代码实现如下:
#import "MainTableViewController.h" @interface MainTableViewController () @property (nonatomic, retain)NSMutableArray *arr; @property(nonatomic, retain)UIRefreshControl *RefreshControl; @end @implementation MainTableViewController - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.arr = [NSMutableArray arrayWithObjects:@"宋江", @"卢俊义", @"吴用", @"公孙胜", @"关胜", @"林冲", @"秦明" ,@"呼延灼" , @"花容",@"柴进", @"李应", @"朱仝",@"鲁智深",@"武松",nil]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // 系统默认的刷新, 下拉 self.RefreshControl = [[UIRefreshControl alloc] init]; self.RefreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"正在刷新"]; [self.view addSubview:self.RefreshControl]; [self.RefreshControl addTarget:self action:@selector(changeVaule:) forControlEvents:UIControlEventValueChanged]; } - (void)changeVaule:(UIRefreshControl *)refresh{ // 先关闭刷新效果, 若不关闭就会一直显示. [refresh endRefreshing]; NSString *str = @"哈哈"; [self.arr insertObject:str atIndex:0]; [self.tableView reloadData]; }
这是创建文件时就已经写好的协议方法
#pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { #warning Potentially incomplete method implementation. // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { #warning Incomplete method implementation. // Return the number of rows in the section. return self.arr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *reuse = @"reuse"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:reuse] autorelease]; } cell.textLabel.text = self.arr[indexPath.row]; cell.textLabel.font = [UIFont systemFontOfSize:20]; // Configure the cell... return cell; }
当然, 协议中还有其他方法,比如, 有一个系统自带的快捷菜单
#pragma mark 设置是否允许给tableView上的cell添加快捷菜单方法.(协议中的) - (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath{ return YES; } #pragma mark 这个方法是设置是否允许给tableView的cell添加事件. - (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{ return YES; } #pragma mark 当点击菜单上的按钮之后,会出现的方法. - (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{ if (action == @selector(copy:)) { NSLog(@"copy"); } }
相关文章推荐
- win10无法升级Win10 Build 10532?也许Hyper-V在搞鬼
- 【Android UI设计与开发】第05期:引导界面(五)实现应用程序只启动一次引导界面
- UI设计-不简单?简单(2)
- UI 15 NetWorkingTool 封装JSON解析
- uva 11538 - Chess Queen 先分步还是先分类? 计数问题
- 【Android UI设计与开发】第04期:引导界面(四)仿人人网V5.9.2最新版引导界面
- STL源码剖析 [容器](五)[stl_deque.h]
- 【Android UI设计与开发】第03期:引导界面(三)仿微信引导界面以及动画效果
- ORA-00001: unique constraint (...) violated并不一定是数据冲突
- ORA-00001: unique constraint (...) violated并不一定是数据冲突
- 【Android UI设计与开发】第02期:引导界面(二)使用ViewPager2、其中小点的图片用一个selector来控制颜色,point.xml:现欢迎引导页面
- 【Android UI设计与开发】第01期:引导界面(一)ViewPager介绍和使用详解
- LeetCode -- Distinct Subsequences
- UILable写出类似Cell的UITableViewCellStyleSubtitle状态下效果
- iOS开发陷阱之UITextField中文输入长度的限制
- 开关控件UISwitch
- UI:MVC设计模式
- 百度编辑器Ueditor的黑白名单过滤
- UIBezierPath + CAShapeLayer (弧形 + 线条)
- UICollectionView flowlauout 瀑布流效果