Xcode 错误:预期标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8024638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:20:32  来源:igfitidea点击:

Xcode error : Expected identifier

objective-ciosxcodeuitableviewuitabbarcontroller

提问by James Kerstan

I Get an error stating "Expected Identifier" at this line of code

我在这行代码中收到一条错误消息,指出“预期标识符”

UINavigationController *navController1 = [[[UINavigationController alloc] initWithRootViewController:viewController4]];  

This code is placed in the application Delegate as follows

这段代码放在应用Delegate中如下

#import "AppDelegate.h"

#import "FirstViewController.h"

#import "SecondViewController.h"

#import "ParkTable.h"
#import "TableTest.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
@synthesize ParkTableDel = _tableViewController;
@synthesize navController;




- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UITableViewController *viewController3 = [[ParkTable alloc] initWithNibName:@"ParkTable" bundle:nil];
UITableViewController *viewController4 = [[TableTest alloc] initWithNibName:@"TableTest" bundle:nil];
UINavigationController *navController1 = [[[UINavigationController alloc] initWithRootViewController:viewController4]];  

self.tabBarController = [[UITabBarController alloc] init];
self.ParkTableDel = [[UITableViewController alloc] init];

self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, viewController4, nil];
self.window.rootViewController = self.tabBarController;    
[self.window makeKeyAndVisible];
return YES;
}

// [...] Boilerplate code removed.
@end

I was wondering what i have to change to make it correct.

我想知道我必须改变什么才能使它正确。

回答by Luke

Could it be the extra set of parentheses? [ ]

可能是额外的一组括号吗?[ ]

回答by Freddy

As pointed out by Luke you have an extra set of parentheses.

正如 Luke 所指出的,你有一组额外的括号。

To correct the black screen try..

要纠正黑屏尝试..

[self.window addSubview: self.tabBarController.view]

Instead of ..

代替 ..

self.window.rootViewController = self.tabBarController; 

回答by Mayank Kapoor

Had the same problem. It is probably the extra set of [] you have around your line of code.

有同样的问题。它可能是您的代码行周围的额外 [] 集。