我正在使用这个方法来初始化一个 nsmutablearray
- (void)getAllContacts
{
Contact *contact = [[Contact alloc] init];
self.allContacts = [[NSMutableArray alloc] init];
int i=0;
for (i=0; i<5; i++)
{
contact.nome = [[NSString alloc] initWithFormat:@"Bruno %d", i];
[self.allContacts insertObject:contact atIndex:i];
}
}
很简单!但是之后,我做了一个 for 来打印它的元素,例如:
for (int i=0; i<[self.allContacts count]; i++)
{
Contact *c = [self.allContacts objectAtIndex:i];
NSLog(@"i=%d\nNome:%@", i, c.nome);
}
它会向我显示最后一个元素“Bruno 4”的 5 次。它不是从 0 开始并递增。我应该怎么做才能从0开始?