-1

InvoiceInfo1 という名前の配列が 1 つあり、それを allInfo という名前の別の配列に渡します。

しかし、invoiceInfo の別のインデックスが必要な場合は、別の配列が作成され、それを allInfo に渡します。

マイコードは次のとおりです。

for (int i=0; i<[userdata count]; i++) {  

    NSLog(@" userdata count :%d",[userdata count]);

    invoiceInfo1 = [NSMutableArray arrayWithObjects:[[userdata objectAtIndex:i]valueForKey:@"fname"],  [[userdata
    objectAtIndex:i]valueForKey:@"name"],

    [[userdata objectAtIndex:i]valueForKey:@"address"],

    [[userdata objectAtIndex:i]valueForKey:@"city"], nil];
    NSLog(@" info1 is:%@",invoiceInfo1); // invoiceInfo get overwrite when loop execute

    NSMutableArray* allInfo = [NSMutableArray arrayWithObjects:headers,invoiceInfo1 ,  nil]; 

    // HERE I Want Generate New Array of different index of invoiceInfo1 & pass it to allInfo

}
4

1 に答える 1

0

header と info 配列を持つ NSObject クラスを作成します。

@interface AllInfo: NSObject
{
    NSMutableArray *header;
    NSMutableArray *info;
}

@property (nonatomic, retain) NSMutableArray *header;
@property (nonatomic, retain) NSMutableArray *info;

@end

@implementation AllInfo

@synthesize header;
@synthesize info;

@end

次に、このコードを実装します。

allInfo = [[NSMutableArray alloc] init];
for (int i=0; i<[userdata count]; i++) {  

    NSLog(@" userdata count :%d",[userdata count]);

    NSMutableArray *invoiceInfo1 = [[NSMutableArray alloc] init]; 
    [invoiceInfo1 addObject:[userdata objectAtIndex:i]valueForKey:@"fname"]];
    [invoiceInfo1 addObject:[userdata objectAtIndex:i]valueForKey:@"name"]];
    [invoiceInfo1 addObject:[userdata objectAtIndex:i]valueForKey:@"address"]];
    [invoiceInfo1 addObject:[userdata objectAtIndex:i]valueForKey:@"city"]];

    NSLog(@" info1 is:%@",invoiceInfo1); // invoiceInfo get overwrite when loop execute
    AllInfo *newInfo = [[AllInfo alloc] init];
    newInfo.header = headers;
    newInfo.info = invoiceInfo1;
    [allInfo addObject:newInfo]; 

    // HERE I Want Generate New Array of different index of invoiceInfo1 & pass it to    allInfo

}

これが役立つことを願っています。

于 2012-08-06T11:33:00.680 に答える