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在不同事件上更新数组。