UITableViewController

MyTableViewController.m

#import "MyTableViewController.h"

@interface MyTableViewController ()
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)UIRefreshControl *control;
@end

@implementation MyTableViewController

-(void)dealloc
{
    [_arr release];
    [super dealloc];
}

-(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.control=[[UIRefreshControl alloc]init];
    self.control.attributedTitle=[[NSAttributedString alloc]initWithString:@"正在加载数据..."];
    [self.view addSubview:self.control];
    [self.control addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];    
}

-(void)changeValue:(UIRefreshControl *)control
{
    // 先关闭刷新的效果
    [control endRefreshing];
    [self.arr addObject:@"limuran"];
    [self.tableView reloadData];    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {   
    static NSString *resue=@"resue";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:resue];

    if (!cell) {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resue]autorelease];
    }
    cell.textLabel.text=self.arr[indexPath.row];    
    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;
}

// 最后一步:点击菜单上得按钮之后会触发的方法
-(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{    
    if(action == @selector(copy :)){
        NSLog(@"拷贝");
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值