gpt4 book ai didi

objective-c - 获取编译器错误预期标识符/预期方法主体

转载 作者:行者123 更新时间:2023-11-28 22:46:48 26 4
gpt4 key购买 nike

我目前正在开发一个应用程序, Storyboard中有 2 个主要 View ; View Controller 和主视图 Controller 。

我在 MainViewController.m 中遇到了 Expected IdentifierExpected 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

最佳答案

您似乎混淆了方法声明(在本例中为覆盖),并且实际上是在 Objective-C 中发送消息。您的方法 body 应如下所示:

- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil //No more errors.

要在消息中使用该方法,请调用 [[MyClass alloc]initWithNibName:@"MainViewController"bundle:nil];

作为旁注:-init... 风格的消息几乎从不被类本身调用,因为它没有什么意义,如果“正确”实现,会创建一些有趣的保留周期。

关于objective-c - 获取编译器错误预期标识符/预期方法主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13004406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com