2014-10-02 176 views
0

這是我在xcode中添加新視圖控制器的原始問題;xcode中的新視圖控制器?

Adding a View Controller in Xcode?

這是我觀察到的代碼,即負荷出在Xcode一個新的項目爲一個視圖或者Controller.h /米文件

.H

@interface ViewController : UIViewController 

{ 


} 

@end 

.M

@interface ViewController() 

@end 

@implementation ViewController 

但是,當我添加一個新的類;我注意到沒有'UIViewController'對象,而是有一個NSOBject。

.H

@interface Newclass : NSObject 
@end 

.M

@implementation Newclass 
@end 

我的問題;要成功以編程方式訪問x代碼故事板中的新視圖控制器,是否必須將新的自定義.m/.h文件格式化爲UIViewController或者是否重要。

回答

1

是的,要繼承UIViewController需要的屬性&必須'格式化'爲(正確的術語是'繼承自')一個UIViewController。所以:

@interface Newclass : UIViewController 
@end 

@implementation Newclass 
@end 
+0

謝謝你生病嘗試 – godman 2014-10-02 19:36:39

+0

爲什麼不是UIViewController中使用,而不是NSObject的新類型 – godman 2014-10-03 06:24:35

相關問題