0

我有一个随机生成的数组,我将该内容存储到 Nsmutablearray 中。

我的内容像这样 1 2 3 4 5 6 7 8

我的要求是,当用户删除第 3 个数字并单击下一步按钮时,将显示第 4 个索引数据这是我的场景,我该怎么做...

我试过这段代码

        NSLog(@"%u",[delegate.Bookmarknamearray count]-1);
        NSLog(@"%d",delegate.selectId);

            if([delegate.Bookmarknamearray count]-1==delegate.selectId)
            {
                if(([delegate.Bookmarknamearray count]-1)==0)
                {
                    [self.navigationController popToRootViewControllerAnimated:YES];
                }
                else
                {
                    NSLog(@"%u",[delegate.Bookmarknamearray count]-1);
                    NSLog(@"%d",delegate.selectId);

                    txttrickname.text=[delegate.Bookmarknamearray objectAtIndex:delegate.selectId-1];
                    txtview.text=[delegate.BookmarkDetailarray objectAtIndex:delegate.selectId-1];

                    NSLog(@"%@",txttrickname.text);
                    NSLog(@"%@",txtview.text);

                    [delegate.Bookmarknamearray removeObject:delegate.str];
                    self.navigationItem.title = [NSString stringWithFormat:@"%d/%d", (delegate.selectId), [delegate.Bookmarknamearray count]];

                    NSLog(@"%@",self.navigationItem.title);
                }
            }

            else
            {


                    if([delegate.Bookmarknamearray count]==1)
                    {

                        [self.navigationController popToRootViewControllerAnimated:YES];

                    }
                else
                {


                    NSLog(@"%lu",(unsigned long)[delegate.Bookmarknamearray count]);

                    NSLog(@"%d",delegate.selectId);
                    NSLog(@"%d",delegate.counter);

                    txttrickname.text=[delegate.Bookmarknamearray objectAtIndex:delegate.selectId+1];
                    txtview.text=[delegate.BookmarkDetailarray objectAtIndex:delegate.selectId+1];

                    NSLog(@"%@",txttrickname.text);
                    NSLog(@"%@",txtview.text);

                   [delegate.Bookmarknamearray removeObject:delegate.str];
                    self.navigationItem.title = [NSString stringWithFormat:@"%d/%d", (delegate.selectId+1), [delegate.Bookmarknamearray count]];

                    NSLog(@"%@",self.navigationItem.title);
                }
            }


    }

提前致谢..

4

2 回答 2

1

正如您所说,您已经将这些值存储到一个可变数组中,您需要做的是,要删除第三个数字,请写下:

[yourArray removeObjectAtIndex:2];

因此,您的第 4 个号码将成为第 3 个号码。

你在找这个吗?

于 2013-08-07T06:05:45.290 回答
0

试试这个。。

-(IBAction)remove:(UIButton *)sender
{

   for(NSMutableDictionary *dict in YOUR_ARRAY){
        if([[dict objectForKey:@"id"]integerValue]==sender.tag){
            [dict removeAllObject];
        }
    }

}
于 2013-08-07T05:59:55.517 回答