Ios UITableView中的可展开行设置为打开
我已设法使TableView可扩展。问题是,当我启动应用程序时,它总是打开的。我希望它被关闭,并在我撞到那排时被打开 我错过了什么?如何在开始时将其设置为打开Ios UITableView中的可展开行设置为打开,ios,objective-c,tableview,Ios,Objective C,Tableview,我已设法使TableView可扩展。问题是,当我启动应用程序时,它总是打开的。我希望它被关闭,并在我撞到那排时被打开 我错过了什么?如何在开始时将其设置为打开 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 3; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sect
- (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;
}
首先创建一个常规表,其中包含一些布尔值数组,用于保存每行的打开/关闭状态 然后,当您点击节中的第一行时,我会用新行重新加载表:
- (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
{
}
}