我正在使用plist保存一些数据如下, 保存方法
NSMutableArray * highScores = [NSMutableArray arrayWithObjects:
[NSNumber numberWithInt:597],
[NSNumber numberWithInt:452],
[NSNumber numberWithInt:365],
nil];
[defaults setObject:highScores forKey:@"high_scores"];
加载方法
NSMutableArray * highScores = [defaults objectForKey:@"high_scores"];
for(NSNumber * score in highScores) {
NSLog(@"Score: %i", [score intValue]);
if (score >=100) {
--> OPEN A SPECIFIC UIVIEWCONTROLLER ON THE STORYBOARD
NSLog(@">100");
}
}
当我加载数据时说,如果分数> 100使用以下代码,我希望它在我的故事板上打开一个特定的uiviewcontroller。我可以知道我该怎么做?
谢谢
答案 0 :(得分:1)
使用此代码
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
viewcontroller *obj = [story instantiateViewControllerWithIdentifier:@"viewcontrollerID"];
[self.navigationController pushViewController:obj animated:YES];
为此您必须提供故事板ID。为此,请参阅此link for storyboardID
的答案答案 1 :(得分:1)
尝试这样可以帮助你。
NSMutableArray * highScores = [defaults objectForKey:@"high_scores"];
for(NSNumber * score in highScores) {
NSLog(@"Score: %i", [score intValue]);
if (score >=100) {
--> OPEN A SPECIFIC UIVIEWCONTROLLER ON THE STORYBOARD
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:[NSBundle mainBundle]];
YourViewcontroller* detail = [storyboard instantiateViewControllerWithIdentifier:@"YourViewcontroller"];
[self presentViewController:detail animated:YES completion:nil];
NSLog(@">100");
}
}