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

UITableViewをUIAlertViewにネストするには、UIActionSheetを使用する方がはるかに優れたアプローチです。

于 2013-02-20T00:08:41.490 に答える
0

willPresentAlertView で tableview をリロードしてみてください。ちなみに、PopUpTableViewController が UITableViewController のサブクラスである場合は、tableview とそのデリゲートとデータソースを再度設定する必要はないと思います。これらはすべて alloc および init 時に自動的に設定されるためです。

于 2013-02-19T23:16:50.890 に答える