編集:私のプロジェクトで使用されるすべての配列はNSMutableArray
クラスです
私がやりたいことの概要は私のselectClueViewからのもので、ユーザーは3から10までの数字を選択できます。彼らがプレイする手がかりの数を表します。次に、0 から の間の乱数のリストを生成し、dataArray として知られる別の配列にobjectArray.count
追加します。どの転送先をNSNumber
含め、すべてが正常に機能していますprepareForSegue
SelectClueViewController.dataArray
GamePageViewController.clueToSelect
ただし、ds
すべてのオブジェクトを保持する配列から、新しい配列にデータをロードすることに固執していますallDataObject
。私はiOSにかなり慣れていません.C#で機能していたので、Objective-Cで複製しようとしましたが、残念ながら完全には複製できないようです.
allDataObject
つまり、配列のデータを配列ds
のNSNumber
値で配列に追加しようとしていますcluesToSelect
。
以下は、使用されるコーディングです。問題を解決するための助けをいただければ幸いです。他に提供すべき情報がある場合は、お知らせください。
SelectClueViewController.m
- (IBAction)onGoPress:(id)sender {
[self chooseNumber];
NSLog(@"Array got %d numbers",dataArray.count);
}
-(void)chooseNumber
{
[dataArray removeAllObjects];
maxCount = [numberOfClues.text intValue];
int count = 0;
do {
NSInteger rdmNumber = arc4random()%objectArray.count;
if (![dataArray containsObject:[NSNumber numberWithInt:rdmNumber]])
{
NSNumber* number = [NSNumber numberWithInt:rdmNumber];
[dataArray addObject:number];
count++;
NSLog(@"random no - %d",rdmNumber);
}
} while (count < maxCount);
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"sendNumber"]) {
GamePageViewController *gpViewController = [segue destinationViewController];
gpViewController.cluesToSelect = self.dataArray;
NSLog(@"Success");
}
}
GamePageViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
daoDS = [[ClueDataDAO alloc]init];
self.allDataObject = daoDS.PopulateDataSource;
NSLog(@"%d",cluesToSelect.count);
[self fillDataSample];
//for keyboard
self.answer.delegate = self;
}
-(void)fillDataSample
{
int count = 0;
do {
// [self.ds addObject:[allDataObject objectAtIndex:[[cluesToSelect objectAtIndex:count]intValue] ]];
ds = [[NSMutableArray alloc]init];
currentClueData = [[ClueData alloc]init];
int firstIndex = [[cluesToSelect objectAtIndex:count]intValue];
currentClueData = [allDataObject objectAtIndex:firstIndex];
[ds addObject:currentClueData];
count++;
} while (count < cluesToSelect.count);
NSLog(@"ds got %d object",ds.count);
}
編集:
オブジェクトを配列に追加できるようになりましたがds
、残念ながら一度しか追加できません。誰かが私のfillDataSample
機能を見ることができますか?