在xcode中一个接一个地执行循环值

时间:2015-02-02 12:58:32

标签: ios objective-c xcode nsmutablearray

viewDidLoad中添加此代码:

NSMutableArray   *array = [NSMutableArray arrayWithObjects:
                               @"Hefeweizen", @"IPA", @"Pilsner", @"Stout", nil];

    NSLog(@"array %@",array);

这是我得到的NSLog

array (
    Hefeweizen,
    IPA,
    Pilsner,
    Stout
)

如何逐个获取值,而不是在NSLog中显示总值,例如:

array{hefeweizen} 
array{IPA}
array{Pilsner}
array{Stout}

3 个答案:

答案 0 :(得分:0)

Ex 1: array[0],array[1]....;

Ex 2: [array objectAtIndex:0]..;

答案 1 :(得分:0)

 //Initialise More data
    setMoreArray = [[NSMutableArray alloc] init];
    NSMutableDictionary *setData = [[NSMutableDictionary alloc] init];[setData setObject:@"profile.png" forKey:@"icon"];[setData setObject:@"inloyal Profile" forKey:@"lable"];[setMoreArray addObject:setData]; 

some thing like this   ??

op:

array ->

(

{
 "icon" = "profile.png"
},
{
 "lable" = "inloyal Profile"
}
)

答案 2 :(得分:0)

我尝试了这段代码并且工作正常:

NSUInteger index;

int64_t delayInSeconds = 5.0;

NSMutableArray   *array = [NSMutableArray arrayWithObjects:
                           @"Hefeweizen", @"IPA", @"Pilsner", @"Stout", nil];

NSMutableArray   *arrayac = [[NSMutableArray alloc]init];



index = 0;

for ( id item in array )
{




    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);

    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){



        [arrayac insertObject:item atIndex:index];
        NSLog(@"dest array %@   ",arrayac);
        NSLog(@"last object in the array %@   ",[arrayac lastObject]);

        testLabel.text = [arrayac lastObject];


    }); 


    delayInSeconds += 1;

    index++;




}

我将此代码放在viewDidLoad中,并且在运行代码之后,恰好在5秒延迟之后,标签以1秒的间隔一个接一个地改变。我想要显示数组中的所有值逐一显示。