我重視的Objective-C試圖創建在NSArray中每個項目的標籤 - 不工作
,看起來就像圖像的陣列和我所試圖做的是以下幾點:
- 運行爲一個foreach此的NSArray
- 陣列中創建的每個項目的標籤(SO 3個司標籤,3個項目標籤,3個工作單標籤和3組裝標籤)
我有以下代碼:
int counter = 0;
for (id object in _theParamenterArray) {
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 30*counter + 10, 200, 200)];
label.text = [object objectForKey:@"Assemble"];
[label setFont:[UIFont boldSystemFontOfSize:16]];
[self.view addSubview:label];
UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(110, 30*counter + 10, 200, 200)];
label.text = [object objectForKey:@"Division"];
[label setFont:[UIFont boldSystemFontOfSize:16]];
[self.view addSubview:labelTwo];
UILabel *labelThree = [[UILabel alloc]initWithFrame:CGRectMake(210, 30*counter + 10, 200, 200)];
label.text = [object objectForKey:@"Project"];
[label setFont:[UIFont boldSystemFontOfSize:16]];
[self.view addSubview:labelThree];
UILabel *labelFour = [[UILabel alloc]initWithFrame:CGRectMake(310, 30*counter + 10, 200, 200)];
label.text = [object objectForKey:@"WorkOrder"];
[label setFont:[UIFont boldSystemFontOfSize:16]];
[self.view addSubview:labelFour];
counter++;
}
我用這個代碼的問題是,它只有在共造成4個標籤和數據是數組中的最後一個項目,所以纔出現了壓倒一切的價值觀。我的問題我該如何解決這個問題?請幫忙!
你確定你的循環執行了三次嗎?我注意到調試器中顯示的數組和代碼中的數組有不同的名稱 – Paulw11