我正在开发一个应用程序,我在故事板中有两个主要的视图; ViewController和MainViewController。
我在MainViewController.m中遇到Expected Identifier
和Expected method body
错误。
这是文件:
//
// MainView.m
// Ski Finder Intro
//
// Created by Hunter Bryant on 10/20/12.
// Copyright (c) 2012 Hunter Bryant. All rights reserved.
//
#import "MainViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (id)initWithNibName:@"MainViewController" bundle:Nil //Here are both of the errors.
{
self = [super initWithNibName:@"MainViewController'" bundle:Nil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:2)
您似乎混淆了方法声明(在本例中为覆盖),并且实际上是在Objective-C中发送消息。您的方法正文应如下所示:
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil //No more errors.
要在消息中使用该方法,请致电[[MyClass alloc]initWithNibName:@"MainViewController" bundle:nil];
作为旁注:-init...
风格的消息几乎从未被类本身调用,因为它没有多大意义,并且如果“正确”实现则会创建一些有趣的保留周期。