我有一個工作區,其中有兩個項目。第一個項目本質上是一個測試和開發項目,我在開始工作之前先把所有的東西都捆綁在一起,然後才真正做到了。第二個項目是將所有我個人開發的視圖控制器放在故事板中。類別標題導入不工作
在其中一個視圖控制器上,我有一堆輕掃手勢,其中有一些UIView動畫調用的格式很好,因此可讀性很好,因此佔用了大量空間。我選擇將它們作爲一個類別移出。
問題是編譯器沒有在主頭文件中看到實例變量聲明。
我拉我的頭髮是什麼,我在第一個項目中做到了這一點,它一切正常。所以我仔細比較了我的第二個項目的內容和第一個項目的內容,我沒有看到任何區別。
我這裏還有一些文件內容,可以幫助演示如何/在那裏我定義的東西,然後的代碼片段中的類文件試圖訪問它們:
GSBViewController.h
@interface GSBViewController : UIViewController
@property (strong, nonatomic) IBOutlet UISegmentedControl *roundPicker;
@property (strong, nonatomic) IBOutlet UIView *roundsSectionView;
GSBViewController.m
#import "GSBViewController+Swipe.h"
@interface GSBGameBuilderViewController()
{
UIBarButtonItem *rightGatherBarButton;
NSInteger previousRound;
}
@end
@implementation GSBViewController
@synthesize roundPicker;
@synthesize roundsSectionView;
GSBViewController + Swipe.h
#import "GSBViewController.h"
@interface GSBViewController (Swipe)
- (void)establishSwipeGestures;
@end
GSBViewController + Swipe.m
#import "GSBViewController+Swipe.h"
@implementation GSBViewController (Swipe)
- (void)establishSwipeGestures
{
UISwipeGestureRecognizer *swipeLeft =
[[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(roundsSectionLeft:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeLeft setNumberOfTouchesRequired:1];
[roundsSectionView addGestureRecognizer:swipeLeft];
// bunch-o-code snipped -- for the time being it's actually all commented out
// as a test and because the LLVM compiler was giving up after too many errors
// and I wanted to see if there was more it would like to tell me about this first --
// and very representative -- problem.
}
@end
從編譯器的抱怨是「未聲明的標識符的‘roundsSectionView’使用」
如果我在該行的代碼中使用roundsSectionView的選項,單擊我在其中添加手勢識別器,彈出窗口正確地將其描述爲在GSBViewController.h中聲明。
所以我很難過。
有什麼我可以在Xcode中做的(4.3.2在發佈時:-)讓我看看包含的文件是什麼?或者是否有一些非基於文件的內容需要將類別綁定到正在增強的類中?我不記得以前有必要這樣的事情。實際上,我爲這個類別生成文件的方式是通過Xcode的File - > New File ... Objective-C Category模板。然後,我只複製了舊的... + Swipe.h和... + Swipe.m文件的內容,並將它們粘貼到新項目中它們各自的文件中。
謝謝, CHIRAG。仔細看看我的「舊」代碼確實顯示了爲這些變量定義的支持變量。並將它們添加到「新」代碼滿足編譯器。 – tobinjim
許多人使用樣式'@synthesize aVariable = _aVariable;' - 是否也爲該物業創建了「支持伊娃」? – tobinjim
是的。 '@synthesize var = _anything_'創建一個支持變量。 '_varName'只是一個約定,所以你不會錯誤地使用'varName'而不是'self.varName'。 – chirag