2013-09-23 65 views
-1

我有一個名爲Letters的NSMutableArray,它包含UIImageView子類的實例。我試圖通過它們循環,併爲它們分配新的值無法在iOS中分配表達式

for (int i=0 ;i<26;i++) 
{ 
    [letters objectAtIndex:i] = [[typeLetters alloc]initWithManager:self atX:startX andY:startY withSideLenght:48 andName:[letterNames objectAtIndex:i] andPng:[letterNames objectAtIndex:i]]; 
} 

雖然這不起作用。 Xcode說:「不能分配到表達式」,但是當我嘗試分配給每個數組項目的新值,數組之外,它的工作原理。你知道這是爲什麼嗎?

編輯:沒關係。對不起。我應該多看看陣列。

+0

那不是你怎麼做。閱讀NSMutableArray的文檔 - 請! –

回答

1

的方法你正在尋找is.-

- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject; 

for (int i=0 ;i<26;i+=1) { 
    [letters replaceObjectAtIndex:i withObject:[[typeLetters alloc]initWithManager:self atX:startX andY:startY withSideLenght:48 andName:[letterNames objectAtIndex:i] andPng:[letterNames objectAtIndex:i]]]; 
} 
+0

不錯,謝謝。很好 –

0

數組符號工作原理:letters[i] = blah

但你或許應該使用快速列舉:

for(id letter in letters) { letter = blah; }

相關問題