从另一个NsMutableArray填充NSMutableArray(Fill NSMutableArray from another NsMutableArray)
我有两个类
indexViewController
和flashCardQuestionViewController
。在
indexViewController
我有一个表填充了一个数组。现在我从数据库中获取一些数据:
-(void)getMultipleChoiceAnswer { if(optionid!=nil) [optionid removeAllObjects]; else optionid = [[NSMutableArray alloc] init]; if(optionText!=nil) [optionText removeAllObjects]; else optionText = [[NSMutableArray alloc] init]; clsDatabase *clsDatabaseObject = [[clsDatabase alloc] init]; sqlite3_stmt *dataRows = [clsDatabaseObject getDataset:"select optionID,OptionText from flashCardMultipleAnswer where questionId=1"]; while(sqlite3_step(dataRows) == SQLITE_ROW) { [optionid addObject:[NSNumber numberWithInt:sqlite3_column_int(dataRows,0)]]; [optionText addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(dataRows,1)]]; } sqlite3_finalize(dataRows); [clsDatabaseObject release]; }
我在
indexViewController
的viewDidLoad
方法中调用此方法。现在我在名为
listNoOfOptionsInQuestion
的flashCardQuestionViewController
有另一个NSMutableArray
。我想用
optionText
数组中的对象填充indexViewController
。我怎样才能做到这一点?
I have two classes
indexViewController
andflashCardQuestionViewController
.In the
indexViewController
i have table filled with an array.Now i am getting some data from the database:
-(void)getMultipleChoiceAnswer { if(optionid!=nil) [optionid removeAllObjects]; else optionid = [[NSMutableArray alloc] init]; if(optionText!=nil) [optionText removeAllObjects]; else optionText = [[NSMutableArray alloc] init]; clsDatabase *clsDatabaseObject = [[clsDatabase alloc] init]; sqlite3_stmt *dataRows = [clsDatabaseObject getDataset:"select optionID,OptionText from flashCardMultipleAnswer where questionId=1"]; while(sqlite3_step(dataRows) == SQLITE_ROW) { [optionid addObject:[NSNumber numberWithInt:sqlite3_column_int(dataRows,0)]]; [optionText addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(dataRows,1)]]; } sqlite3_finalize(dataRows); [clsDatabaseObject release]; }
and I am calling this method in the
viewDidLoad
method of theindexViewController
.Now I have another
NSMutableArray
in theflashCardQuestionViewController
namedlistNoOfOptionsInQuestion
.I want to fill
listNoOfOptionsInQuestion
with objects fromoptionText
array inindexViewController
.How can I do this?
原文:https://stackoverflow.com/questions/948870