2016-08-31 2 views
0

Мой вопрос: как отрегулировать большой текст и фиксированный размер изображения в UITableViewCell.
Мне нужна ячейка autoresize согласно данным, подобным WhatsApp. Как мне это сделать. Моя ячейка изменяет размер, когда я использую UILabel, но в случае изображения это испортило все.Авторезистировать ячейку в соответствии с текстом UILabel и изображениями как чат

Пожалуйста, предложите мне. Заранее спасибо.

@ddb это мой исходный код, который я использую.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return UITableViewAutomaticDimension; 
} 

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return UITableViewAutomaticDimension; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return [adminDataArray count]; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *[email protected]"admincell"; 
    adminCell =[tableView dequeueReusableCellWithIdentifier:identifier]; 
    if (adminCell==nil) { 
     adminCell=[[AdminPostTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; 
    } 
    adminCell.selectionStyle=UITableViewCellSelectionStyleNone; 
    [adminCell setBackgroundColor:[UIColor clearColor]]; 
    NSMutableDictionary *getAdminDataDictionary=[adminDataArray objectAtIndex:indexPath.row]; 
    if ([getAdminDataDictionary objectForKey:@"TEXT"]) 
    { 
     adminCell.lblSenderAdminPage.text=[getAdminDataDictionary objectForKey:@"TEXT"]; 
     adminCell.lblSenderAdminPage.textColor=[UIColor blackColor]; 
     adminCell.lblSenderAdminPage.backgroundColor=[UIColor whiteColor]; 
     adminCell.lblSenderAdminPage.preferredMaxLayoutWidth=305; 
     adminCell.lblSenderAdminPage.layer.masksToBounds=YES; 
     adminCell.lblSenderAdminPage.layer.cornerRadius=5; 
     adminCell.lblSenderAdminPage.layer.borderWidth=1.0f; 
     adminCell.lblSenderAdminPage.layer.borderColor=[UIColor blackColor].CGColor; 
    } 
    else if ([getAdminDataDictionary objectForKey:@"IMAGE"]){   
     adminCell.imgSenderAdminPage.image=[getAdminDataDictionary objectForKey:@"IMAGE"]; 
    } 
    return adminCell; 
} 
+0

доли текущий исходный код, пожалуйста – ddb

+0

Попробуйте эту ссылку http://stackoverflow.com/a/14841373/4970453 –

ответ

0

Вы можете попробовать использовать

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

    CGSize messageSize // Your message size 
    if (img) { 
     CGFloat imgHeight = img.size.height; // Image size 
     return messageSize.height + imgHeight + 2* textMarginVertical; 
    } else { 
     return messageSize.height + 2* textMarginVertical; 
    } 
} 

В верхней части класса объявить

static CGFloat textMarginVertical = 7f; 

Счастливый кодирования ..

+0

Что такое "img"? –

+0

Ваш файл изображения, который вы хотите установить в ячейке. –

+0

Но при кодировании дается ошибка «Свойство« размер »не найден на объекте типа« UIImageView * », когда я устанавливаю размер как: - –