- 我在
Xcode
它默認包括ViewController
文件創建的單個視圖的項目。 - 我創建了一個名爲
MyClass
的NSObject
子類。 - I
#import <UIKit/UIKit.h>
inMyClass
。 MyClass
確認到UITableViewDelegate
和UITableViewDatasource
- 實現的
UITableViewDelegate
和UITableViewDatasource
- 所需的方法我創建了一個
xib
文件,並在UIView的我拖着放棄了UITableView
。 - 我將xib文件
files owner
類設置爲MyClass
。 - 在xib文件中設置
UITableView
委託和數據源。 在
ViewController
viewDidAppear
我這樣做的UITableView使用XIB文件,NSObject的子類,並使用在UIViewController中UIView *subView1=[[[NSBundle mainBundle] loadNibNamed:@"View1" owner:self options:nil] objectAtIndex:0]; MyClass *c = [[MyClass alloc]init]; [self.view addSubview:subView1];
但我對[self.view addSubview:subView1];
-[ViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x10027adc0
得到這個錯誤在Xcode控制檯我做po 0x10027adc0
這是ViewController
我試圖創建一個功能UITableView使用xib file
和NSObject
子類,所以我可以在UIViewController
類中重用它。
我做錯了什麼?
你寫過'numberOfRowsInSection'方法嗎? –
@the_UB是它的numberOfRowsInSection方法,我收到錯誤消息。 –
顯示'numberOfRowsInSection'方法。 –