UITableViewController

来源:互联网 发布:淘宝可以不交保证金吗 编辑:程序博客网 时间:2024/06/05 06:55

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(@"拷贝");    }}
0 0
原创粉丝点击