UITableView

动态管理表高度     原则就是先计算显示内容的高度

- (float)tableView:(UITableView*)tableView  heightForRowAtIndexPath:(NSIndexPath*)indexPath {
    if(tblviewSign==tableView){//签名
        CGSizesize=[personInfor.codeContentsizeWithFont:[UIFontsystemFontOfSize:12]constrainedToSize:CGSizeMake(260,88)lineBreakMode:NSLineBreakByWordWrapping];
        [tblviewSignframeSetHeight:44+size.height+20];//设置表的高度
        return44+size.height;
    }
    return42;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [self tableView:tableView heightForRow:indexPath];
}
//此方法是自定义方法,方法内容是cellForRow中的方法copy过来,然后稍作修改即可(就算以后cell内容也修改,此方法也不用大改),然后在heightForRowAtIndexPath协议方法中调用
- (CGFloat)tableView:(UITableView *)tableView heightForRow:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
    SUStoreChatlogs *chatlog = [arrayMsg objectAtIndex:indexPath.row];
    float returnCellHeight = 0.0;
    cell = [self makeCustomCell:tableView identifier:@"receivedIdentifier" loadNibNamed:@"MsgCellReceived"];
    SUVButtonReceived *bubbleReceived = (SUVButtonReceived *)[cell viewWithTag:4];
    UIImageView *imgviewAvatar = (UIImageView *)[cell viewWithTag:1];
    UILabel *lblTime = (UILabel *)[cell viewWithTag:3];
    
    [self viewReceived:chatlog bubble:bubbleReceived lbl:lblTime];
    returnCellHeight = MAX(bubbleReceived.frame.size.height + bubbleReceived.frame.origin.y, lblTime.frame.size.height + imgviewAvatar.frame.size.height);
    return returnCellHeight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
    SUSeekuDbHelper *db = [[SUSeekuDbHelper alloc]init];
    SUStoreChatlogs *chatlog = [arrayMsg objectAtIndex:indexPath.row];
    
    cell = [self makeCustomCell:tableView identifier:@"receivedIdentifier" loadNibNamed:@"MsgCellReceived"];
    SUVButtonReceived *bubbleReceived = (SUVButtonReceived *)[cell viewWithTag:4];
    UIImageView *imgviewAvatar = (UIImageView *)[cell viewWithTag:1];
    UILabel *lblTime = (UILabel *)[cell viewWithTag:3];
    //头像
    [imgviewAvatar setImageWithURL:[NSURL URLWithString:personMsg.avatar] placeholderImage:[SUPackMethod dgGetDefaultAvatarFromSex:(SU_SEX)personMsg.sex]];
    
    [self viewReceived:chatlog bubble:bubbleReceived lbl:lblTime];
    
    CGRect cellFrame = cell.frame;
    cellFrame.size.height = bubbleReceived.frame.size.height + bubbleReceived.frame.origin.y;
    cell.frame = cellFrame;
    
    [db release];
    return cell;
}

刷新表时定位问题

if ([arrayMsgcount] > 0) {
    //这个条件必须要做判断,因为如果arrayMsgcount为0的话,[arrayMsgcount]-1为负,会导致崩溃
    [tblviewSMSreloadData];
    [tblviewSMSscrollToRowAtIndexPath:[NSIndexPathindexPathForRow:[arrayMsgcount]-1 inSection:0]atScrollPosition:UITableViewScrollPositionBottomanimated:NO];
}

表单元格样式 (单元格样式的内容可以在layoutSubviews中定义)

@interface SUInviteByPhoneCell : UITableViewCell

@end

@implementation SUInviteByPhoneCell

- (void) layoutSubviews {
    [super layoutSubviews];
    self.textLabel.font = [UIFont systemFontOfSize:15];
    
    self.detailTextLabel.font = [UIFont systemFontOfSize:15];
    self.detailTextLabel.textColor = [UIColor colorToGRB:@"9e9e9e"];
    self.detailTextLabel.backgroundColor = [UIColor clearColor];
    self.detailTextLabel.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    self.detailTextLabel.textAlignment = UITextAlignmentCenter;
    //这里定义了accessoryView的坐标大小
    self.accessoryView.frame = CGRectMake(265, 6, 25, 25);
}
@end

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    
    SUInviteByPhoneCell *cell = (SUInviteByPhoneCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[SUInviteByPhoneCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }
    
    return cell;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值