2016-07-01 2 views
0

Может кто-нибудь предложить мне, как реализовать следующее в Objective C?Развертывание и сворачивание разделов

Когда я нажимаю на строки раздела только для этого отдельного раздела. Как узнать, какой раздел нажат, и как мне вернуть количество строк для этого раздела?

Примечание: У меня есть кнопка в моей секции. И когда я нажимаю строки всех разделов, их расширяют и снова, когда я нажимаю на строки разделов всех разделов, обрушиваются.

+0

См ссылке: http://stackoverflow.com/questions/17248021/how-to-expand-and-collapse-rows-using-header-section-in-a-uitableview –

+0

Возможный дубликат [ Развертывание и сворачивание разделов tableView iOS?] (Http://stackoverflow.com/questions/27729150/expanding-and-collapsing-tableview-sections-ios) – Jidong

ответ

1

Примечание: - Моя TableView высота ячейки 126, но когда я запускаю мое приложение, высота TableCell составляет 75 (Как я уже ниже), когда я нажал на TableCell, чем автоматически TableCell высота расширяться.

См.: - int myCurrentSelection = 9999; // Установить глобально.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

int myrow = (int)indexPath.row; 

if (myCurrentSelection == myrow) { 
    myCurrentSelection = 9999; 
    cell.contentView.backgroundColor = [UIColor whiteColor]; 
} else { 
    myCurrentSelection = myrow; 
    cell.contentView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0]; 
} 
[tableView beginUpdates]; 
[tableView endUpdates]; 
[self.tblView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; 
} 


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CGSize boundingBox = [mutArrMessages [indexPath.row][@"message"] boundingRectWithSize:CGSizeMake((self.tblView.frame.size.width - 86),MAXFLOAT) 
                       options:NSStringDrawingUsesLineFragmentOrigin 
                      attributes:@{NSFontAttributeName:[UIFont helveticaNeueLightFontOfSize:17.0]} 
                       context:nil].size; 
CGSize size = CGSizeMake(ceil(boundingBox.width), ceil(boundingBox.height)); 
if ([indexPath row] == myCurrentSelection) { 
    return (MAX((size.height + 46),76)) + 50; 
} 
return (MAX((size.height + 46),76)); 
} 


-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
return 76; 
} 
Смежные вопросы