【问题标题】:@end must appear in an objective-c context@end 必须出现在 Objective-C 上下文中
【发布时间】:2012-08-30 17:29:54
【问题描述】:

我正在关注http://www.raywenderlich.com/14172/how-to-parse-html-on-ios 的教程。

这是我的 detailviewcontroller.h 文件。

#import <UIKit/UIKit.h>

    @end <-- //errors shows up here.

    @interface DetailViewController : UIViewController

    @property (strong, nonatomic) id detailItem;

    @property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
    @end

这是我的 detailview.m 文件

#import "DetailViewController.h"


@interface DetailViewController ()
- (void)configureView;
@end

@implementation DetailViewController

#pragma mark - Managing the detail item

- (void)setDetailItem:(id)newDetailItem
{
    if (_detailItem != newDetailItem) {
        _detailItem = newDetailItem;

        // Update the view.
        [self configureView];
    }
}

- (void)configureView
{
    // Update the user interface for the detail item.

    if (self.detailItem) {
        self.detailDescriptionLabel.text = [self.detailItem description];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self configureView];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Detail", @"Detail");
    }
    return self;
}

@end

正如我上面提到的,@end 错误消息出现并等待自动修复红色方块,我同意进行自动修复。然后 xCode 在那里应用 @end 代码,如 .h 文件中所示。然后出现另一个错误,标题为“@end 必须出现在objective-c 上下文中”

我该怎么办? xCode 疯了还是怎么了。

怎么了?

【问题讨论】:

  • 只需删除第一个@end,然后按Command+B。
  • 但是你知道“结束”的意思吗?

标签: objective-c appearance


【解决方案1】:

就我而言,在某个 .h 文件中我错过了 @end 。因此,导入该 .h 文件的所有文件都提示此错误。有趣的是,我没有在一个确实错过@end 的.h 文件上收到此错误消息。所以我想你需要做一些搜索,确保你用@end 关闭了所有的@interface、@implementation 或@protocol。希望对您有所帮助。

【讨论】:

    【解决方案2】:

    只需删除第一个 @end。这是完全错误的。您只能在 @implementation@interface@protocol 声明之后使用 @end

    【讨论】:

    • @user1529095:但是当你删除它时,什么?
    • 是的,但是当我删除它时,它会要求我再次查看。看看这个视频link
    • @user1529095:我认为您还有其他事情要做。修复它的建议完全是错误的。
    • 我也遇到了这个奇怪的错误。你想好怎么解决了吗?
    猜你喜欢
    • 1970-01-01
    • 2016-03-29
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 2010-10-09
    • 2011-08-29
    • 2017-08-07
    • 1970-01-01
    相关资源
    最近更新 更多