我想將UIButton對象添加到數組,但他們沒有這樣做。每當我調用[像素計數]或[顏色計數]它返回0.我嘗試使用[self.arrayName addObject:myObject]和[arrayName addObject:myObject],但似乎都沒有工作。我對Objective-C非常陌生,所以它可能在我看來很愚蠢,但是這已經讓我停留了一個多小時。無法讓addObject在NSMutableArray上工作
這裏是ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
NSMutableArray *pixels;
NSMutableArray *colors;
}
@property (nonatomic, retain) NSMutableArray *pixels;
@property (nonatomic, retain) NSMutableArray *colors;
@end
代碼這裏是從ViewController.m相關代碼
int x = 30;
int y = 60;
for(int i=0; i<10; i++) {
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x,y,20,20)];
[self.pixels addObject:button];
x += 20;
y += 20;
}
我有整個工程壓縮了其可以在這裏下載: http://mdl.fm/pixelated.zip
在此先感謝任何可以幫助到的人!
你有沒有初始化你的數組? – rdelmar
我會在哪裏初始化它們?我在ViewController.h中試過,但它一直在說Expected「;」在聲明列表的末尾。我也在ViewController.m的init()和ViewController.m的viewDidLoad()裏面嘗試了它,但都沒有成功。 – SISYN
正確,零目標消息被忽略(NSControl除外)。 –