美文网首页
UITableViewCell 预习

UITableViewCell 预习

作者: 雷仔 | 来源:发表于2016-02-24 01:04 被阅读24次

    @property (nonatomic, retain)NSMutableArray *arr;

    @property (nonatomic, retain)UITableView *tbv;

    @end

    @implementation RootViewController

    - (void)dealloc

    {

    [_arr release];

    [_tbv release];

    [super dealloc];

    }

    - (id)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];

    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor lightGrayColor];

    self.navigationController.navigationBar.translucent = NO;

    self.navigationItem.title = @"鸭梨大";

    self.tbv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStyleGrouped];

    self.tbv.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:self.tbv];

    [self.tbv release];

    self.tbv.rowHeight = 100;

    self.tbv.delegate = self;

    self.tbv.dataSource = self;

    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)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:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];

    }

    cell.textLabel.text = self.arr[indexPath.row];

    cell.imageView.image = [UIImage imageNamed:@"S1.jpg"];

    cell.detailTextLabel.text = @"detail";

    cell.accessoryType = UITableViewCellAccessoryDetailButton;

    return cell;

    }

    - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

    {

    NSLog(@"section = %ld, row = %ld", indexPath.section, indexPath.row);

    }

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    DetailViewController *DeVC = [[DetailViewController alloc] init];

    DeVC.indexPath = indexPath;

    [self.navigationController pushViewController:DeVC animated:YES];

    [DeVC release];

    }

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

    {

    return 3;

    }

    - (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

    }

    /*

    #pragma mark - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navig

    相关文章

      网友评论

          本文标题:UITableViewCell 预习

          本文链接:https://www.haomeiwen.com/subject/zyfikttx.html