UITableViewController

来源:互联网 发布:生男生女预测表49算法 编辑:程序博客网 时间:2024/05/23 01:23

////  MyTableViewController.h//  UI15_UITableViewController////  Created by dllo on 15/8/18.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>@interface MyTableViewController : UITableViewController@end

////  MyTableViewController.m//  UI15_UITableViewController////  Created by dllo on 15/8/18.//  Copyright (c) 2015年 flg. All rights reserved.//#import "MyTableViewController.h"@interface MyTableViewController ()@property(nonatomic,retain)NSMutableArray *arr;@property(nonatomic,retain)UIRefreshControl *refresh;@property(nonatomic,retain)UITableViewCell *cell;@end@implementation MyTableViewController- (void)dealloc{    [_arr release];    [_refresh 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];        // Uncomment the following line to preserve selection between presentations.    // self.clearsSelectionOnViewWillAppear = NO;        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.    // self.navigationItem.rightBarButtonItem = self.editButtonItem;    //系统默认的刷新 下拉    self.refresh=[[UIRefreshControl alloc] init];    self.refresh.attributedTitle=[[NSAttributedString alloc] initWithString:@"正在加载..."];    [self.view addSubview:self.refresh];    [self.refresh addTarget:self action:@selector(refreshAction:) forControlEvents:UIControlEventValueChanged];}- (void)refreshAction:(UIRefreshControl *)control{    [control endRefreshing];    [self.arr addObject:@"安逸臣"];    [self.tableView reloadData];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}#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";    self.cell = [tableView dequeueReusableCellWithIdentifier:reuse];    if (!self.cell) {        self.cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];    }    self.cell.textLabel.text=self.arr[indexPath.row];    return self.cell;}#pragma mark 设置是否允许添加菜单- (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(@"拷贝");    }}/*// Override to support conditional editing of the table view.- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {    // Return NO if you do not want the specified item to be editable.    return YES;}*//*// Override to support editing the table view.- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {    if (editingStyle == UITableViewCellEditingStyleDelete) {        // Delete the row from the data source        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];    } else if (editingStyle == UITableViewCellEditingStyleInsert) {        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view    }   }*//*// Override to support rearranging the table view.- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {}*//*// Override to support conditional rearranging of the table view.- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {    // Return NO if you do not want the item to be re-orderable.    return YES;}*//*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {    // Get the new view controller using [segue destinationViewController].    // Pass the selected object to the new view controller.}*/@end


0 0
原创粉丝点击