简体   繁体   中英

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. 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.

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.

So, increasing the height to at least a row's height could call cellForRowAtIndexPath method of the TableView.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM