[英]cellForRowAtIndexPath not called but numberofRowsInSection called for UITableView added as subview to UIView
I have created custom alert view where i want to add the UITableView
as subview.I haven't created UITableView
through (IB)
but created programmatically,Also I have implement protocol UITableViewDelegate
and UITableViewDataSource
in UIView
.But the method cellForRowAtIndexPath
not called. 我创建了自定义警报视图,我想在其中添加UITableView
作为子视图。我没有通过(IB)
创建UITableView
,而是通过编程方式创建的,而且我在UIView
实现了协议UITableViewDelegate
和UITableViewDataSource
。但是未调用方法cellForRowAtIndexPath
。 I think the problem is here i have to create UITableView
through IB make it visible.is it possible not to create through IB
but using below code and implement the delegate methods. 我认为问题在于我必须通过IB创建UITableView
使其可见。是否有可能不是通过IB
创建而是使用以下代码并实现委托方法。
Here is the code 这是代码
privacy_tableview = [[UITableView alloc] initWithFrame:CGRectMake(10.0, 0.0, alert_width-40.0, 0.0)]; [privacy_tableview sizeToFit];
privacy_tableview.frame = CGRectMake(10.0, 0.0, alert_width-40.0, privacy_tableview.frame.size.height);
//Add scrollview which contain uitableview
MsgScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10.0, alert_height, alert_width-20.0, (privacy_tableview.frame.size.height>max_msg_height)?max_msg_height:privacy_tableview.frame.size.height)];
[privacy_tableview setDataSource:self];
[privacy_tableview setDelegate:self];
[privacy_tableview reloadData];
The height of the table is zero privacy_tableview.frame.size.height = 0.0 and according to table view programming basics for iOS, only visible cells are created and shown in table. 表格的高度为零privacy_tableview.frame.size.height = 0.0,并且根据iOS的表格视图编程基础,仅创建可见单元并在表格中显示。
So, increasing the height to at least a row's height could call cellForRowAtIndexPath method of the TableView. 因此,将高度增加到至少一行的高度可以调用TableView的cellForRowAtIndexPath方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.