在for循环中创建动态不同的(UIViewcontroller)实例名称?

时间:2018-03-01 16:55:51

标签: ios objective-c uipageviewcontroller

我想创建一个ViewControllers我的类SlideViewController的数组,并循环遍历它们为它分配不同的变量名称或循环遍历列表并动态地为我的{{1}分配不同的名称数组索引附加如下:

SlideViewController

以上内容并未将问题分配给我的for (int i=0; i<[_jsonArray count]; i++) { NSDictionary *dict = _jsonArray[i]; SlideViewController *firstViewController = [[SlideViewController alloc] initWithNibName:@"SlideView" bundle:nil]; //i want to do like this --- SlideViewController *firstViewController[i] = [[SlideViewController alloc] initWithNibName:@"SlideView" bundle:nil]; NSLog(@"weekly Question.... %@",[dict objectForKey:@"weeklyquestion"]); firstViewController.question.text = [dict objectForKey:@"weeklyquestion"]; [stepsArray addObject:firstViewController]; } JJGMPageViewController *pageViewController = [[JJGMPageViewController alloc] init]; pageViewController.delegate = self; [pageViewController addViewControllers:stepsArray]; [self presentViewController:nav animated:YES completion:nil]; ,而是覆盖了相同的实例。

1 个答案:

答案 0 :(得分:0)

根据我在此行firstViewController.question.text = [dict objectForKey:@"weeklyquestion"];上看到的内容,您可以设置UILabel或UITextView的文本属性。但是,UILabel或UITextView都不能在该状态下初始化。

相反,请在NSString中声明SlideViewController属性,并在for循环中设置其值。然后,在SlideViewController viewDidLoad方法中,将NSString设置为您的标签或textview的text媒体资源。