我想刪除索引1處的對象,但代碼無法編譯。從NSMutableArray中刪除對象
我也不明白這一點:我設置「iphone」字符串到索引0,之後,我從索引0中刪除它,但輸出仍然首先顯示「iphone」。任何人都可以解釋給我嗎?
int main (int argc, const char * argv[])
{
@autoreleasepool {
//create three string objetc
NSString *banana = @"This is banana";
NSString *apple = @"This is apple";
NSString *iphone [email protected]"This is iPhone";
//create an empty array
NSMutableArray *itemList = [NSMutableArray array];
// add the item to the array
[itemList addObject:banana];
[itemList addObject:apple];
// put the iphone to the at first
[itemList insertObject:iphone atIndex:0];
for (NSString *l in itemList) {
NSLog(@"The Item in the list is %@",l);
}
[itemList removeObject:0];
[itemList removeObject:1];// this is not allow it
NSLog(@"now the first item in the list is %@",[itemList objectAtIndex:0]);
NSLog(@"now the second time in the list is %@",[itemList objectAtIndex:1]);
NSLog(@"now the thrid item in the list is %@",[itemList objectAtIndex:2]);
}
return 0;
}
謝謝。這有助於我! – Ben 2012-03-02 04:01:55