0

我将自定义 UITableViewController 放入 UIAlertView。我填充了表格,但没有出现内容。

- (void)addC { // <== This is get called first
    //Create alertView
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];

    //PopUpTableViewController is a subclass of UITableViewController
    PopUpTableViewController *popUpViewController = [[PopUpTableViewController alloc] initWithStyle:UITableViewStylePlain];
    // ..
    popUpViewController.array = ...;
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 8, 300, MIN(8*44, categoricalVariables.count*44)) style:UITableViewStylePlain];
    popUpViewController.tableView = tableView;
    tableView.delegate = popUpViewController;
    tableView.dataSource = popUpViewController;
    popUpViewController.tableView.tag = 1;

    [alertView addSubview:popUpViewController.tableView];

   //Show alertView
    [alertView show];
}

- (void)willPresentAlertView:(UIAlertView *)alertView { 
// This method is an UIAlertViewDelegate method.
// I set here the sizes of alertView and tableView
    UITableView *tableView = (UITableView *)[alertView viewWithTag:1];
    CGRect r0 = tableView.frame;
    r0.size.width = alertView.frame.size.width - 20;
    tableView.frame = r0;

    CGRect r = alertView.frame;
    r.size.height = tableView.frame.size.height + 24;
    alertView.frame = r;     
}
4

2 回答 2

0

尝试在 willPresentAlertView 中重新加载 tableview 顺便说一下,如果 PopUpTableViewController 是 UITableViewController 的子类,我认为不需要再次设置 tableview 及其委托和数据源。因为所有这些都会在你分配和初始化时自动设置。

于 2013-02-19T23:16:50.890 回答
0

使用 UIActionSheet 将 UITableView 嵌套到 UIAlertView 中是更好的方法。

于 2013-02-20T00:08:41.490 回答