横幅VC不会从plist数组加载

时间:2012-11-08 18:34:06

标签: ios xcode iad

我有一个plist填充选项卡栏上的所有内容,包括tableview:选项卡名称,选项卡图标,标题,详细信息,并使VC成为viewControllers数组。 “使用内容视图控制器进行横幅VC分配:viewControllers” - 如果已知,则不接受阵列,仅接受单个VC或多个VC。 标签是可变的,它们可以移动和更改,所以我不能单独编程。如何将未知的选项卡数组传递给bannerview控制器?

下面非常接近,但是横幅vc只会显示plist中的最后一个集合,而不是整个集合......如果我尝试将viewControllers数组传递给它,就会崩溃。

我要问的是......你如何用一个内置5个标签的plist加载banner vc?

提前谢谢。如果我偏离正轨,有人可能会试图偷我。我真的不想把自己限制在onyl 5标签上。

我只是在plist上添加一个键,它会自动将标签广告到更多部分......如何通过bannew VC传递这个?

_tabBarController.viewControllers = viewControllers; //Loads the array viewControllers fine with 5 tabs and icons, but no banner container

_tabBarController.viewControllers = @[[[BannerViewController alloc] initWithContentViewController:viewControllers]] // Crashes on launch

_tabBarController.viewControllers = @[[[BannerViewController alloc] initWithContentViewController:newsNavigationController]] // Loads only the last key in plist and with no icons


     @implementation AppDelegate {
    UITabBarController *_tabBarController;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    CGRect bounds = [[UIScreen mainScreen] bounds];
    self.window = [[UIWindow alloc] initWithFrame:bounds];
    self.window.backgroundColor = [UIColor whiteColor];    

    NSMutableArray * viewControllers = [[NSMutableArray alloc] init];

    NSString * subscriptionListFile = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"My_Subscription.plist"];
    NSDictionary * subscriptionList = [[NSDictionary alloc] initWithContentsOfFile:subscriptionListFile];
    NSArray * subscriptionFolders = subscriptionList[@"Folders"];

    NewsListViewController * newsController = nil;
    UINavigationController * newsNavigationController = nil;

    for (NSDictionary * folderDetails in subscriptionFolders) {

        NSArray * newsItems = folderDetails[@"Items"];
        NSString * folderTitle = folderDetails[@"FolderName"];
        NSString * folderIcon = folderDetails[@"FolderIcon"];
        UIImage * folderIconImage = [UIImage imageNamed:folderIcon];

        newsController = [[NewsListViewController alloc] initWithNewsSourceList:newsItems];
        [newsController setTitle:folderTitle];
        newsNavigationController = [[UINavigationController alloc] initWithRootViewController:newsController];
        [newsNavigationController setTitle:folderTitle];
        [newsNavigationController.tabBarItem setImage:folderIconImage];
        [viewControllers addObject:newsNavigationController];

    }

    _tabBarController = [[UITabBarController alloc] init];



//  _tabBarController.viewControllers = viewControllers;   <--- this line works, below doesnt load the array...


    _tabBarController.viewControllers = @[[[BannerViewController alloc] initWithContentViewController:viewControllers]]


         self.window.rootViewController = _tabBarController;
        [self.window makeKeyAndVisible];
        return YES;
    }
@end        //The above crashes, but works fine if I SKIP "BannerViewController alloc..." 
            //and go right to "_tabBarController.viewControllers = viewControllers"  

            //perfect but no adbanner :(

1 个答案:

答案 0 :(得分:0)

方法initWithContentViewController:,从其名称(控制器而非控制器)可以看出,只接受一个视图控制器作为其参数。由于该方法是UIPopoverController的一种方法,因此不太清楚你正在尝试做什么,并且你通常不会将一个弹出控制器设置为tabBar控制器中的一个控制器。 s viewControllers。