簡體   English   中英

@class之前的預期標識符或'('錯誤

[英]Expected identifier or '(' error before @class

我有這兩個課程:

ViewController.h

#import <UIKit/UIKit.h>
#import "UICustomButton.h"

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate>{
...

ViewController.m

#import "ViewController.h"

@implementation ViewController
...

UICustomButton.h

#import <UIKit/UIKit.h>
@class ViewController;

@interface UICustomButton : UIButton{
...

UICustomButton.m

#import "UICustomButton.h"
#import "ViewController.h"

@implementation UICustomButton
...

我得到以下錯誤

1預期的標識符或'('-在@class之前的UICustomButton.h文件中

2預期為')'-也有

3預期的類型-當我嘗試在UICustomButton.h中使用ViewController時

4在UiCustomButton.m中我也收到錯誤

經過兩個小時的谷歌搜索和嘗試,我只是看不到問題所在。 你能幫忙嗎?

解決方案:重寫所有內容都是一個很好的想法。 它使我看到在文件ViewController.m中,我不小心在文件開頭的頂部鍵入了一個括號'('。編譯器沒有將其退出,只有UICustomButton.H生成錯誤。

看來您在拼錯ViewController.h。 #import行中有Viewcontroller.h

不要害怕重新啟動/取消並重新創建一個類。 隨着您獲得更多的經驗,更正復雜錯誤變得更加容易。

我非常認真地考慮您需要重新開始創建此類。 由於顯然您無法解釋編譯器告訴您的消息,因此與創建另一個類,在其中復制業務邏輯並刪除當前實現相比,找出問題所需的時間更長。 您可以選擇花10分鍾重新創建文件,或者花另一個人花很多時間來嘗試獲取語法Ok。

甚至專業人士都認為它是在需要時重新啟動的強大工具。 來自Treehouse的Marshall Huss 在此播客中解釋為什么對他來說也更受歡迎。

PS:最好,一旦完成,您可以將新類重命名為舊名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM