【发布时间】:2016-04-23 13:55:21
【问题描述】:
- 我在
Xcode中创建了一个单视图项目,默认情况下包含ViewController文件。 - 我创建了一个名为
MyClass的NSObject子类。 - 我在
MyClass#import <UIKit/UIKit.h>。 -
MyClass确认UITableViewDelegate和UITableViewDatasource - 实现了
UITableViewDelegate和UITableViewDatasource所需的方法 - 我创建了一个
xib文件,并在UIView 中拖放了UITableView。 - 我将xib文件
files owner类设置为MyClass。 - 在 xib 文件中设置
UITableView委托和数据源。 -
在
ViewControllerviewDidAppear我做到了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
我正在尝试使用 xib file 和 NSObject 子类创建 UITableView 的功能,以便我可以在 UIViewController 类中的任何地方重用它。
我做错了什么?
【问题讨论】:
-
你写
numberOfRowsInSection方法了吗? -
@the_UB 是的,我收到错误消息的 numberOfRowsInSection 方法。
-
显示
numberOfRowsInSection方法。
标签: ios objective-c uiviewcontroller xib nsobject