Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.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
Iphone 如何保存tableview单元格的数据_Iphone_Objective C - Fatal编程技术网

Iphone 如何保存tableview单元格的数据

Iphone 如何保存tableview单元格的数据,iphone,objective-c,Iphone,Objective C,我正在表格视图中使用自定义复选框按钮,希望将选定单元格的数据保存到可变数组中。。。。谁能帮我。。。感谢您必须手动执行此操作,UITableView或UITableViewController中没有自动执行此操作的工具。您必须手动执行此操作,UITableView或UITableViewController中没有自动执行此操作的功能。当用户选择任何单元格时,可以在didSelectRowAtIndexPath中动态添加选定对象 [someMutableArr addObject:[tableArr

我正在表格视图中使用自定义复选框按钮,希望将选定单元格的数据保存到可变数组中。。。。谁能帮我。。。感谢您必须手动执行此操作,UITableView或UITableViewController中没有自动执行此操作的工具。

您必须手动执行此操作,UITableView或UITableViewController中没有自动执行此操作的功能。

当用户选择任何单元格时,可以在didSelectRowAtIndexPath中动态添加选定对象

[someMutableArr addObject:[tableArr objectAtIndex:indexPath.row]];

当用户选择任何单元格时,在didSelectRowAtIndexPath中,您可以动态添加选定对象

[someMutableArr addObject:[tableArr objectAtIndex:indexPath.row]];
试试这个

- (void)onButtonClick {

    int numberOfSections = [tableView numberOfSections];

    for (int section = 0; section < numberOfSections; section++) {

        int numberOfRows = [tableView numberOfRowsInSection:section];

        for (int row = 0; row < numberOfRows; row++) {

            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
            UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

            if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {

                // Cell is selected
               //here you can add that values into an array
            } else {

                // Cell is not selected
            }
        }
    }
}
试试这个

- (void)onButtonClick {

    int numberOfSections = [tableView numberOfSections];

    for (int section = 0; section < numberOfSections; section++) {

        int numberOfRows = [tableView numberOfRowsInSection:section];

        for (int row = 0; row < numberOfRows; row++) {

            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
            UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

            if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {

                // Cell is selected
               //here you can add that values into an array
            } else {

                // Cell is not selected
            }
        }
    }
}

创建一个可变数组来存储所选数据,让我们将其称为“yourSeparatedData”,在CellForRowatingIndexPath中设置复选框的标记,并将onCheck:method设置为目标。代码如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier = @"setMe";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyle………
    }
    checkBox = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    checkBox.frame = CGRectMake(customizeMe);
    if(yourSeparatedData && [yourSeparatedData indexOfObject:[yourTableViewDataSource objectAtIndex:indexPath.row]] != NSNotFound)
    {
        [checkBox setBackgroundImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
    }
       else {
        [checkBox setBackgroundImage:[UIImage imageNamed:@"unCheck.png"] forState:UIControlStateNormal];
        }
        [checkBox addTarget:self action:@selector(onCheck:) forControlEvents:UIControlEventTouchUpInside];
        [checkBox setTag:indexPath.row];

        [cell addSubview:checkBox];
        return cell;
}


此代码未经测试,您正在使用复选框,因此我假设您不希望仅分离一个数据,在选择结束时,您将使用从tableView中拾取的对象创建“yourSeparatedData”。

创建一个可变数组来存储所选数据,我们将其称为“yourSeparatedData”,在CellForRowatingIndexPath中设置复选框的标记,并将onCheck:method设置为目标。代码如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier = @"setMe";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyle………
    }
    checkBox = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    checkBox.frame = CGRectMake(customizeMe);
    if(yourSeparatedData && [yourSeparatedData indexOfObject:[yourTableViewDataSource objectAtIndex:indexPath.row]] != NSNotFound)
    {
        [checkBox setBackgroundImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
    }
       else {
        [checkBox setBackgroundImage:[UIImage imageNamed:@"unCheck.png"] forState:UIControlStateNormal];
        }
        [checkBox addTarget:self action:@selector(onCheck:) forControlEvents:UIControlEventTouchUpInside];
        [checkBox setTag:indexPath.row];

        [cell addSubview:checkBox];
        return cell;
}

此代码未经测试,您使用的是复选框,因此我假设您希望分离的不仅仅是一个数据,在选择结束时,您将使用从tableView中拾取的对象获得“yourSeparatedData”

您可以尝试在UITableView单元格中为按钮prees执行自定义操作,也可以使用“放置”复选框图像,单击可以更改图像,因为选中的是代码

这里我有一个id_数组,在选择一个单元格时,我只是删除该索引处的对象

您可以尝试在UITableView单元格中为按钮prees执行自定义操作,也可以使用“放置”复选框图像,单击可以更改图像,因为选中的是代码

这里我有一个id_数组,在选择一个单元格时,我只是删除该索引处的对象


你已经有了数据,你只需要获取特定数据并将其存储到另一个可变数组,对吗?你已经有了数据,你只需要获取特定数据并将其存储到另一个可变数组,我说的对吗?我使用的是自定义按钮…所以我不能通过点击行将它们添加到数组中…我应该怎么做???我使用的是自定义按钮…所以我不能通过点击行将它们添加到数组中…我应该怎么做???