2014-02-16 1 views
0

Мне удалось сделать TableView расширяемым. Проблема в том, что когда я запускаю приложение, он всегда открывается. Я хочу, чтобы он был закрыт и был открыт только, когда я ударил по строке.Расширяемые строки в UITableView установлены для открытия

Что мне здесь не хватает? Как я могу открыть его при запуске?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 3; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 5; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    if (!indexPath.row) 
    { 
     // first row 
     cell.textLabel.text = @"Expandable"; // only top row showing 
    } 
    else 
    { 
     cell.textLabel.text = @"Some Detail"; 
     cell.accessoryView = nil; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 
    return cell; 
} 

- (BOOL)tableView:(UITableView *)tableView canCollapseSection:(NSInteger)section 
{ 
    return YES; 
} 

ответ

0

Сначала необходимо создать регулярную таблицу с некоторым набором булевых, который содержит состояние каждой строки (открыть/закрыть).

Затем, когда вы попали в первую строку в разделе, я перезагрузить таблицу с новыми строками:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //subject hitted 
    if (indexPath.row == 0) 
    { 
     // set relevant boolean here ,also , reload the table again with the new rows 
     collapsedRows[indexPath.section]= ! collapsedRows[indexPath.section]; 
     [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section]withRowAnimation:UITableViewRowAnimationFade]; 
    } 
     //sub subject hitted 
    else 
    { 

    } 
} 
Смежные вопросы