我想使用多维数组。任何人都可以解释如何在iPhone应用程序中使用它吗?我是Objective-C的新手。
这是我正在尝试做的事情:
谢谢, Aaryan
(我到目前为止的代码)
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *arrSeprate = [[NSMutableArray alloc]init];
NSString *temp;
// it is a mysql query//
insertqry = @"INSERT INTO `userDecks` VALUES (1,2,618),(1,3,1471),(1,4,0),(1,5,0),(1,6,7784),(1,11,0),(1,12,469),(1,13,0),(1,16,0),(1,17,113),(1,18,0),(1,19,752),(1,20,60),(1,21,0),(1,30,0),(1,31,0),(1,32,159),(1,34,129),(1,46,143),(1,47,0),(1,53,105),(1,55,456),(1,65,0),(1,66,127),(1,67,131)";
//step-1 ----------begin--------
NSArray *listItems = [insertqry componentsSeparatedByString:@"),"];
//step-1 ----------end--------
int i=0;
//step-2 ----------begin--------
for (i = 1; i<[listItems count]; i++)
{
temp = [listItems objectAtIndex:i];
temp = [temp stringByReplacingOccurrencesOfString:@"(" withString:@"INSERT INTO `userInvitation` VALUES ("];
[arrSeprate addObject:temp];
}
//step-2 ----------end-------------
//step-3 ----------begin--------this will use the for loop to ll elemts of previous array
NSString *middleqry = [arrSeprate objectAtIndex:0];
NSArray *ItemsArray = [middleqry componentsSeparatedByString:@","];
NSLog(@"%@",ItemsArray);
}
答案 0 :(得分:1)
很简单,您可以将itemsArray添加到您创建的可变数组中。这实现了与多维阵列相同的效果。或者,您可以使用带指针的C多维数组。