Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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 我们可以通过单击按钮从NSMutableArray中删除值吗_Iphone_Nsmutablearray - Fatal编程技术网

Iphone 我们可以通过单击按钮从NSMutableArray中删除值吗

Iphone 我们可以通过单击按钮从NSMutableArray中删除值吗,iphone,nsmutablearray,Iphone,Nsmutablearray,我有一个NSMutableArray,当任何用户选择字段时,我会在其中插入值,这是一个多选字段,因此我可以根据NSMutableArray中的多选插入数据,但当用户取消选择字段时,我如何删除未选择字段的值更早。yourviewcontroller.h NSMutableArray *arr_select; NsMutableArray *your_arry; Yourviewcontroller.m - (void)viewDidLoad { arr_select=[[NSMutabl

我有一个
NSMutableArray
,当任何用户选择字段时,我会在其中插入值,这是一个多选字段,因此我可以根据
NSMutableArray
中的多选插入数据,但当用户取消选择字段时,我如何删除未选择字段的值更早。

yourviewcontroller.h

 NSMutableArray *arr_select;
 NsMutableArray *your_arry;
Yourviewcontroller.m

- (void)viewDidLoad
{
  arr_select=[[NSMutableArray alloc]init];   

   for (int i = 0; i < [your_arry count]; i++)
    {
        [arr_select addObject:@"0"];
        [arr_select retain];
    }


}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath   *)indexPath
{
    NSLog(@"%@",arr_select);

    NSNumber *anumber = [NSNumber numberWithInteger:indexPath.row];

    if([[arr_select objectAtIndex:indexPath.row] isEqualToString:@"0"])
    {
        [arr_select replaceObjectAtIndex:indexPath.row withObject:@"1"];
        [arr_select retain];
    }
    else
    {
        [arr_select replaceObjectAtIndex:indexPath.row withObject:@"0"];
        [arr_select retain];
    }


    NSLog(@"%@",arr_select);


    [tableView reloadData];


}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


  if([[arr_select objectAtIndex:indexPath.row]isEqualToString:@"0"])
        {

            cell.accessoryType = UITableViewCellAccessoryNone;
        }
        else
        {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }

}


-(IBAction)Done:(id)sender
{
    NSLog(@"%@",arr_select);
    NSLog(@"%@",co_arr);
    arr_data = [[NSMutableArray alloc] init];

    for (int i = 0; i <[arr_select count]; i++)
    {
        if([[arr_select objectAtIndex:i] isEqualToString:@"1"])
        {
            NSLog(@"%d",i);

            [arr_data addObject:[co_arr objectAtIndex:i]];
            [arr_data retain];
        }
    }
-(void)viewDidLoad
{
arr_select=[[NSMutableArray alloc]init];
对于(int i=0;i<[您的到达计数];i++)
{
[arr_select addObject:@“0”];
[arr_select retain];
}
}
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
NSLog(@“%@”,arr_select);
NSNumber*anumber=[NSNumber numberWithInteger:indexPath.row];
if([[arr_select objectAtIndex:indexath.row]isEqualToString:@“0”])
{
[arr_select replaceObjectAtIndex:indexath.row with object:@“1”];
[arr_select retain];
}
其他的
{
[arr_select replaceObjectAtIndex:indexath.row with object:@“0”];
[arr_select retain];
}
NSLog(@“%@”,arr_select);
[tableView重新加载数据];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
if([[arr_select objectAtIndex:indexath.row]isEqualToString:@“0”])
{
cell.accessoryType=UITableViewCellAccessoryNone;
}
其他的
{
cell.accessoryType=UITableViewCellAccessoryCheckmark;
}
}
-(iAction)完成:(id)发送方
{
NSLog(@“%@”,arr_select);
NSLog(@“%@”,co_arr);
arr_data=[[NSMutableArray alloc]init];

对于(int i=0;我使用NSDictionary进行此操作。在tableview上填充数组???在tableview上填充数组意味着..用户可以选择tableview上的数据吗?您应该尝试使用NSNotificationCenter在不同事件上更新数组。