在AppDelegate中设置TabviewController时,使用UIViewController传递参数

时间:2014-05-30 17:51:47

标签: ios

当我在标签栏中创建标签时,我想传递参数。每次应用程序启动时,这些参数都会更改。但是我得到了物业'传递了#UR;没有找到类型对象' UIViewController'在

finalVC.passedURL = @"http://www.google.com";

FinalCategoryVC.h:

@property(nonatomic, retain) NSString *passedURL;

AppDelegate.m:

#import "FinalCategoryVC.h"

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

    UIViewController  *finalVC = [[[FinalCategoryVC alloc] initWithNibName:@"FinalCategoryVC" bundle:nil] autorelease];

    finalVC.passedURL = @"http://www.google.com";

    self.tabBarController = [[[UITabBarController alloc] init] autorelease];   
    self.tabBarController.viewControllers = @[finalVC]; 
   self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    self.tabBarController.customizableViewControllers = nil;
    return YES;
}

1 个答案:

答案 0 :(得分:0)

你得到了这个错误,因为你将FinalCategoryVC转换为带有这一行的UIViewController,

UIViewController  *finalVC = [[[FinalCategoryVC alloc] initWithNibName:@"FinalCategoryVC" bundle:nil] autorelease];

将其更改为此以解决问题,

FinalCategoryVC  *finalVC = [[[FinalCategoryVC alloc] initWithNibName:@"FinalCategoryVC" bundle:nil] autorelease];