0
我是iOS新手,初學者是關於編程的。多值集索引名稱
我對編程有一些疑問。
問題
我有5 NSMutableArray裏,我想所有的NSMutableArray添加到1 NSMutableArray的
按照本準則。
在.h文件中
@property (strong, nonatomic) NSMutableArray *orderType1;
@property (strong, nonatomic) NSMutableArray *orderType2;
@property (strong, nonatomic) NSMutableArray *orderType3;
@property (strong, nonatomic) NSMutableArray *orderType4;
@property (strong, nonatomic) NSMutableArray *orderType5;
@property (strong, nonatomic) NSMutableArray *allData;
在.m文件
for(int i = 0; i < orderCount; i++) // orderCount is count of orderType(count = 5)
{
// Do something about condition to get Data...
// ... This Condition will Receive "data"
// Add Object
if (i == 0)
[_orderType1 addObject:data];
else if (i == 1)
[_orderType2 addObject:data];
else if (i == 2)
[_orderType3 addObject:data];
else if (i == 3)
[_orderType4 addObject:data];
else
[_orderType5 addObject:data];
}
_allData = [NSArray arrayWithObjects:_orderType1, _orderType2, _orderType3, _orderType4, _orderType5, nil];
結果這個代碼是工作和正確的。但我想要索引i的_orderType的名稱。
例如:在循環
for(int i = 0; i < orderCount; i++) // orderCount is count of orderType(count = 5)
{
// Do something about condition to get Data...
// ... This Condition will Receive "data"
// Add Object
[_orderType[i] addObject:data]
}
如何解決,或者我不能在這種情況下解決這個問題。
謝謝你,並對我的錯誤感到抱歉。
你有沒有想過用* allData代替數組使用NSMutableDictionary? –