我是 iPhone 新手,我想将元素添加到 NSMutableArray 中,每个元素的名称为我为 keys 创建了一个 MutableArray,然后为我从名为 Pages 的对象中获取的元素创建了另一个数组。
我写了以下代码
NSMutableArray *myArray;
NSMutableArray *arrayKey = [[NSMutableArray alloc] initWithObjects:@"b_pag_id", @"b_pag_bo_id", @"b_pag_num", @"b_pag_note", @"b_page_mark", @"b_page_stop", @"b_pag_user_id", nil];
for (int x=0; x<[pages count]; x++) {
Pages *myPages = (Pages *)[self.pages objectAtIndex:x];
NSString *b_pag_id2 = [NSString stringWithFormat:@"%d",myPages.b_pag_id];
NSString *b_pag_bo_id2 = [NSString stringWithFormat:@"%d",myPages.b_pag_bo_id];
NSString *b_pag_num2 = [NSString stringWithFormat:@"%d",myPages.b_pag_num];
NSString *b_pag_note2 = myPages.b_pag_note;
NSString *b_page_mark2 = [NSString stringWithFormat:@"%d",myPages.b_page_mark];
NSString *b_page_stop2 = [NSString stringWithFormat:@"%d",myPages.b_page_stop];
NSString *b_pag_user_id2 = [NSString stringWithFormat:@"%d",myPages.b_pag_user_id];
NSMutableArray *arrayValue = [[NSMutableArray alloc] initWithObjects:b_pag_id2, b_pag_bo_id2, b_pag_num2, b_pag_note2, b_page_mark2, b_page_stop2, b_pag_user_id2, nil];
NSDictionary *theReqDictionary = [NSDictionary dictionaryWithObjects:arrayValue forKeys:arrayKey];
myArray = [NSMutableArray arrayWithObjects:theReqDictionary,nil];
}
NSLog(@"array size: %d", [myArray count]);
我想将每个元素添加到它的键中,例如元素 (b_pag_id2) 它的键 (b_pag_id) ..etc 这是对的吗?或如何做到这一点?考虑到 NSLog(@"array size: %d", [myArray count]); 给我 1 我元素的大小是 14