0
현재 메시징 응용 프로그램을 만들고 있지만 최근에는 tableCell이 예상대로 크기가 조정되지 않습니다. 나는 새로운 iOS 8 상대적 높이 기능을 사용했지만 여전히 변화는 없습니다. Storyboard를 통해 모든 디자인이 진행되고 있지만 지금까지 예상대로 작동하지만 textCell에 따라 크기를 조정하려면 tableCell에 알려야합니다. 여기 어떻게 현재 찾고 있어요. UITableCell에게 UItextview의 높이를 동적으로 알려주십시오.
http://i.imgur.com/lqoxxJV.png
내가 사용 강령
은 다음과 같다.- (UITableViewCell*)tableView:(UITableView*)table cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary* chatMessage = [_conversation objectAtIndex:indexPath.row];
// Show If type is String
if ([chatMessage[@"type"] isEqualToString:@"string"]) {
// if its me
if([chatMessage[@"user_sender"] isEqualToString:_user_sender]){
NSString *CellIdentifier = @"fromMe";
FromMeTableViewCell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];
[cell.message_me setNeedsLayout];
[cell.message_me layoutIfNeeded];
cell.message_me.clipsToBounds = YES;
cell.message_me.textContainerInset = UIEdgeInsetsMake(8.0, 8.0, 7.0, 8.0);
cell.message_me.text = chatMessage[@"msg"];
cell.message_date_me.text = [NSString stringWithFormat:@"%@", chatMessage[@"message_date"]];
cell.avatar_message_me.clipsToBounds = YES;
cell.avatar_message_me.layer.cornerRadius = cell.avatar_message_me.frame.size.width /2;
cell.avatar_message_me.image = [UIImage imageNamed:@"amber.png"];
return cell;
}
// it its other user
else {
NSString *CellIdentifier = @"fromThem";
FromThemTableViewCell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];
[cell.message_them setNeedsLayout];
[cell.message_them layoutIfNeeded];
cell.message_them.clipsToBounds = YES;
cell.message_them.textContainerInset = UIEdgeInsetsMake(8.0, 8.0, 7.0, 8.0);
cell.message_them.text = chatMessage[@"msg"];
cell.message_date_them.text = [NSString stringWithFormat:@"%@", chatMessage[@"message_date"]];
cell.avatar_message_them.clipsToBounds = YES;
cell.avatar_message_them.layer.cornerRadius = cell.avatar_message_them.frame.size.width /2;
cell.avatar_message_them.image = [UIImage imageNamed:@"jenny.png"];
return cell;
}
}
// Show if type is Image File
else if ([chatMessage[@"type"] isEqualToString:@"img"]){
// if its me
if(![chatMessage[@"user_sender"] isEqualToString:_user_sender]){
NSString *CellIdentifier = @"fromThemImage";
FromThemImageTableCell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];
cell.image_type_them.image = [UIImage imageNamed:@"foto.jpeg"];
cell.message_date_them.text = [NSString stringWithFormat:@"%@", chatMessage[@"message_date"]];
return cell;
}
// if its other user
else {
NSString *CellIdentifier = @"fromMeImage";
FromMeImageTableCell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];
cell.image_type_me.image = [UIImage imageNamed:@"foto.jpeg"];
cell.message_date_me.text = [NSString stringWithFormat:@"%@", chatMessage[@"message_date"]];
return cell;
}
}
else if ([chatMessage[@"type"] isEqualToString:@"file"]){
NSLog(@"Type: %@", chatMessage[@"type"]);
NSString *CellIdentifier = @"fromThemFile";
FromThemFileTableCell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];
cell.message_date_them.text = [NSString stringWithFormat:@"%@", chatMessage[@"message_date"]];
cell.file_name_them.text = chatMessage[@"msg"];
cell.file_type_them.contentMode = UIViewContentModeScaleAspectFill;
NSArray *formats = [chatMessage[@"msg"] componentsSeparatedByString:@"."];
// PDF Format
if ([formats[1] isEqualToString:@"pdf"]) {
cell.file_type_them.image = [UIImage imageNamed:@"pdf.png"];
}
// Word Format
if ([formats[1] isEqualToString:@"doc"]) {
cell.file_type_them.image = [UIImage imageNamed:@"doc.png"];
}
if ([formats[1] isEqualToString:@"docx"]) {
cell.file_type_them.image = [UIImage imageNamed:@"doc.png"];
}
// Power Point Format
if ([formats[1] isEqualToString:@"pptx"]) {
cell.file_type_them.image = [UIImage imageNamed:@"ppt.png"];
}
if ([formats[1] isEqualToString:@"ppt"]) {
cell.file_type_them.image = [UIImage imageNamed:@"ppt.png"];
}
// Excel Format
if ([formats[1] isEqualToString:@"xls"]) {
cell.file_type_them.image = [UIImage imageNamed:@"xls.png"];
}
if ([formats[1] isEqualToString:@"xlsx"]) {
cell.file_type_them.image = [UIImage imageNamed:@"xls.png"];
}
return cell;
}
else {
// Remember to set this as a default value
NSString *CellIdentifier = @"fromThem";
FromThemTableViewCell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];
cell.message_them.text = chatMessage[@"msg"];
cell.message_date_them.text = [NSString stringWithFormat:@"%@", chatMessage[@"message_date"]];
return cell;
}
}
텍스트 뷰를 확장하여 보일 수있는 제약 조건은 다음과 같습니다.
http://i.imgur.com/Kjva3ES.png
어떤 생각 방법이 괜찮은 방법에 해결하는 ..? 당신의 UITableViewCells 인해 내용의 변화에 높이가 다를 경우