如何在UIViewController中显示UITableView?
我正在从UITableViewController 推送detailViewController (UIViewController)。 DetailViewController 由 UITextView 和小型 UITableView 组成。我已将我的detailViewController 设置为实现UITableViewDataSource 和UITableViewDelegate 协议的UIViewController。我在IB 中有委托和数据源出口。我有那些必需的表委托和数据源方法,当DetailViewController 被推到顶部时会调用这些方法。我被称为设置部分数量 (1) 和部分行数 (2) 的方法。问题是当detailViewController位于顶部时,我在屏幕上看不到我的tableView。
我注意到 Xcode 警告我详细视图控制器中的 initWithStyle 它可能不会响应 [super initWithStyle:style]:
- (id)initWithStyle:(UITableViewStyle)style{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
我知道它不属于 UIViewController 但如何解决问题?
更新:看来我的 tableView 被缩小了。我已经在 IB 中为其设置了足够的高度和宽度,但看起来 tableView 在屏幕上显示的一行非常窄,并且当表格填满行时它不会调整大小。恕我直言,它在某种程度上与无法调用 initWithStyle 有关。有没有人以其他方式实现类似的解决方案?
I'm pushing detailViewController (UIViewController) from UITableViewController. detailViewController consists of UITextView and small UITableView. I have set my detailViewController to be UIViewController that implements UITableViewDataSource and UITableViewDelegate protocols.I have delegate and datasource outlets in IB. I have those required table delegate and datasource methods that are called when detailViewController is pushed on top. I get called the methods that set number of sections (1) and number of rows in section (2). The problem is I do not see my tableView on screen when detailViewController is on top.
I have noticed that Xcode warns me about initWithStyle in detailViewController that it may not respond to [super initWithStyle:style]:
- (id)initWithStyle:(UITableViewStyle)style{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
I understand that it does not belong to UIViewController but how to get things worked out?
UPDATE: It appears my tableView is shrink-ed. I have set enough height and width for it in IB but it looks like the tableView appears on screen with very narrow one row and it does not resize when the tables fills with rows. IMHO it somehow related to being unable to call initWithStyle. Does anybody achieved similar solution in other ways?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所说,detailViewController 是 UIViewController 的子类。
UIViewController
未实现-initWithStyle:
,因此警告是合法的。你不能从
UITableViewController
继承detailViewController
吗?如果您必须使用
UIViewController
,则必须在detailedViewController
中创建tableView
出口,并且它应该连接到IB中的表。你确定已经完成了吗?As you've said,
detailViewController
is aUIViewController
subclass.UIViewController
does not implement-initWithStyle:
, so the warning is legit.Can't you subclass
detailViewController
fromUITableViewController
?If you have to use
UIViewController
, you'd have to havetableView
outlet created indetailedViewController
and it should be connected to your table in IB. Did you make sure it's done?