我是Xcode和Objective-C中的菜鸟,我需要帮助才能根据标签中的字符数来制作动态表格视图单元格的高度.所以它将是这样的:如果textLabel char超过10,它将把listHeight的大小调整为50,否则如果textLabel char超过20,它会将listHeight的大小调整为70,依此类推......
这是我编码的方式:
NSLong *text;
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = @"ChatTableViewCell";
ChatTableViewCell *cell = (ChatTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ChatTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
Chat * chatObject;
chatObject = [chatArray objectAtIndex:indexPath.row];
cell.nameChat.text = chatObject.name;
cell.messageChat.text = chatObject.message;
cell.messageChat.lineBreakMode = UILineBreakModeTailTruncation;
cell.messageChat.numberOfLines = 0;
cell.dateChat.text = chatObject.time_entry;
//attached foto
NSString *setPhoto=chatObject.photo;
[cell.imageChat setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://localhost/summit/www/media/user/photo/%@",setPhoto]]]]];
cell.imageChat.layer.cornerRadius=cell.imageChat.frame.size.height /2;;
cell.imageChat.layer.masksToBounds = YES;
cell.imageChat.layer.borderWidth = 0; …Run Code Online (Sandbox Code Playgroud)