2013-02-19 26 views
0

我把一个自定义的UITableViewController到UIAlertView中。我填充了表格,但内容没有出现。UITableView的内容不会出现在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;  
} 
+0

你试图在alertview的消息设置为类似@ “\ n \ n \ n \ n”?我的rember一个项目,帮我出 – pmk 2013-02-19 21:59:31

+0

我试过刚才什么都没有,表仍是空的。 – 2013-02-19 22:01:56

回答

0

这是更好的方法来使用UIActionSheet是嵌套一个UITableView到UIAlertView中。

0

尝试重新加载willPresentAlertView 的实现代码如下顺便说一句,如果PopUpTableViewController是的UITableViewController的子类,我觉得就没有必要重新设置的tableview及其委托和数据源。因为所有这些将在您分配和初始化时自动设置。