UITableView代理方法的执行流程

just explain it with code:


//  ViewController.m

#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    _items = [[NSMutableArray alloc] initWithObjects:@"one", @"tow fjdsl fjdslf slfjls flsjflsjf lsjflsjfls jflsjflsjf lsjf lsjflsj flsjflsjflsjf lsfj lsfjslfj ltwo", @"three but so what r fdlsf slf slf jslfj slfj lsf jlsjf lsfjlsfjiosj flsjf lsjf ;sfj s;jf s;jfs jfs; fjs;fj fs ;fslflsflsf lflsflsflsfslolling in the deep, we could have it all!", @"four", @"five", @"six", @"sefjd slfjslf jlsjflsjflsjflsfjlsfj ls fjls fjlsjflsj flsjfljsfljl j lven", @"eight", @"nine", @"ten", nil];
    _tableView = [[UITableView alloc] initWithFrame:self.view.frame];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"%@", NSStringFromSelector(_cmd));
    return _items.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%@", NSStringFromSelector(_cmd));
    return [[_items objectAtIndex:indexPath.row] sizeWithFont:[UIFont boldSystemFontOfSize:18.0f] constrainedToSize:CGSizeMake(280, MAXFLOAT)].height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%@", NSStringFromSelector(_cmd));
    static NSString *cellID = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.contentView.backgroundColor = [UIColor yellowColor];
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.text = [_items objectAtIndex:indexPath.row];
    cell.textLabel.font = [UIFont boldSystemFontOfSize:18.0f];
    CGRect rect = [cell.textLabel textRectForBounds:cell.textLabel.frame limitedToNumberOfLines:0];
    cell.textLabel.frame = rect;
    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%@", NSStringFromSelector(_cmd));
    NSLog(@"1 %f", cell.contentView.frame.size.width);
    NSLog(@"2 %f", cell.contentView.frame.size.height);  // 300
    NSLog(@"3 %f", cell.textLabel.frame.size.width);     // 280
    NSLog(@"4 %f", cell.accessoryView.frame.size.width); // 0  not right
}

- (void)dealloc
{
    [_tableView release], _tableView = nil;
    [_items release], _items = nil;
    [super dealloc];
}

/**
     tableView:numberOfRowsInSection:
     tableView:heightForRowAtIndexPath:
     tableView:heightForRowAtIndexPath:
     tableView:heightForRowAtIndexPath:
     tableView:heightForRowAtIndexPath:
     tableView:heightForRowAtIndexPath:
     tableView:heightForRowAtIndexPath:
     tableView:heightForRowAtIndexPath:
     tableView:heightForRowAtIndexPath:
     tableView:heightForRowAtIndexPath:
     tableView:heightForRowAtIndexPath:
     tableView:cellForRowAtIndexPath:
     tableView:willDisplayCell:forRowAtIndexPath:
     1 300.000000
     2 22.000000
     3 280.000000
     4 0.000000
     tableView:cellForRowAtIndexPath:
     tableView:willDisplayCell:forRowAtIndexPath:
     1 300.000000
     2 66.000000
     3 280.000000
     4 0.000000
     tableView:cellForRowAtIndexPath:
     tableView:willDisplayCell:forRowAtIndexPath:
     1 300.000000
     2 110.000000
     3 280.000000
     4 0.000000
     tableView:cellForRowAtIndexPath:
     tableView:willDisplayCell:forRowAtIndexPath:
     1 300.000000
     2 22.000000
     3 280.000000
     4 0.000000
     tableView:cellForRowAtIndexPath:
     tableView:willDisplayCell:forRowAtIndexPath:
     1 300.000000
     2 22.000000
     3 280.000000
     4 0.000000
     tableView:cellForRowAtIndexPath:
     tableView:willDisplayCell:forRowAtIndexPath:
     1 300.000000
     2 22.000000
     3 280.000000
     4 0.000000
     tableView:cellForRowAtIndexPath:
     tableView:willDisplayCell:forRowAtIndexPath:
     1 320.000000
     2 44.000000
     3 0.000000
     4 0.000000
     tableView:cellForRowAtIndexPath:
     tableView:willDisplayCell:forRowAtIndexPath:
     1 300.000000
     2 22.000000
     3 280.000000
     4 0.000000
     tableView:cellForRowAtIndexPath:
     tableView:willDisplayCell:forRowAtIndexPath:
     1 300.000000
     2 22.000000
     3 280.000000
     4 0.000000
     tableView:cellForRowAtIndexPath:
     tableView:willDisplayCell:forRowAtIndexPath:
     1 300.000000
     2 22.000000
     3 280.000000
     4 0.000000
 */
@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值