UI 15 UITableViewController & 系统自带快捷菜单 & 系统下拉刷新

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");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值