我有不同的UILabels,我想隱藏使用for循環。隱藏NSMutableArray中的所有UILabels
@interface MyViewController : UIViewController {
NSMutableArray * labelArray;
}
@property (nonatomic, retain) IBOutlet UILabel *label1, *label2, *label3;
...
-(void)viewDidLoad {
[super viewDidLoad];
[labelArray initWithObjects:label1,label2,label3,nil];
for(int i=0; i<sizeof(labelArray); i++){
UILabel *label = [labelArray objectAtIndex:i];
label.hidden = !label.hidden;
}
}
執行此操作時,標籤不會隱藏。他們已經在Interface Builder中「迷上」了。我做錯了什麼?謝謝!
1.你有沒有alloc'd labelArray? 2.不要使用sizeof(labelArray),而是使用[labelArray count]來確定索引範圍。不要忘記labelArray是一個指針,sizeof()將返回指針大小。 – viggio24