Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView中的可展开行设置为打开_Ios_Objective C_Tableview - Fatal编程技术网

Ios UITableView中的可展开行设置为打开

Ios UITableView中的可展开行设置为打开,ios,objective-c,tableview,Ios,Objective C,Tableview,我已设法使TableView可扩展。问题是,当我启动应用程序时,它总是打开的。我希望它被关闭,并在我撞到那排时被打开 我错过了什么?如何在开始时将其设置为打开 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 3; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sect

我已设法使TableView可扩展。问题是,当我启动应用程序时,它总是打开的。我希望它被关闭,并在我撞到那排时被打开

我错过了什么?如何在开始时将其设置为打开

- (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
    {

    }
}