簡體   English   中英

未調用cellForRowAtIndexPath,但為UITableView調用的numberofRowsInSection已添加為UIView的子視圖

[英]cellForRowAtIndexPath not called but numberofRowsInSection called for UITableView added as subview to UIView

我創建了自定義警報視圖,我想在其中添加UITableView作為子視圖。我沒有通過(IB)創建UITableView ,而是通過編程方式創建的,而且我在UIView實現了協議UITableViewDelegateUITableViewDataSource 。但是未調用方法cellForRowAtIndexPath 我認為問題在於我必須通過IB創建UITableView使其可見。是否有可能不是通過IB創建而是使用以下代碼並實現委托方法。

這是代碼

        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];

表格的高度為零privacy_tableview.frame.size.height = 0.0,並且根據iOS的表格視圖編程基礎,僅創建可見單元並在表格中顯示。

因此,將高度增加到至少一行的高度可以調用TableView的cellForRowAtIndexPath方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM