将UIActionsheet添加到UIAlertView中

时间:2013-04-23 11:12:44

标签: iphone uitableview uialertview uiactionsheet

如何将uiactionsheet添加到uialertview中? 我还将tableview添加到alertview中,并且还想添加具有四个按钮的动作表 当我写这些代码时,它会给出错误

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Preferences"
                                                    message:@"\n\n\n\n\n\n\n"
                                                   delegate:self
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:@"OK", nil];

    UITableView *myView = [[[UITableView alloc] initWithFrame:CGRectMake(10, 40, 264, 150)
                                                        style:UITableViewStylePlain] autorelease];
    myView.delegate = self;
    myView.dataSource = self;



    [alert addSubview:myView];

   NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title
   NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles
   NSString *other1 = @"Other Button 1";
   NSString *other2 = @"Other Button 2";
   NSString *other3 = @"Other Button 3";
   NSString *cancelTitle = @"Cancel Button";


   UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:actionSheetTitle
                                                            delegate:self
                                                   cancelButtonTitle:cancelTitle
                                              destructiveButtonTitle:destructiveTitle
                                                   otherButtonTitles:other1, other2, other3, nil];

   UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(10, 250, alert.frame.size.width, 250)];
   tempView.backgroundColor = [UIColor redColor];
   tempView.clipsToBounds = YES;
   [alert addSubview:tempView];

   [alert addSubview:actionSheet];
  [alert show];
    [actionSheet showInView:tempView];
     [myView reloadData];

Tableview完全添加但动作表不会添加。 那么有没有可用的解决方案????

提前致谢

2 个答案:

答案 0 :(得分:2)

旧问题,但对于通过谷歌来到这里的任何人,我都会推荐CXAlertView

答案 1 :(得分:1)

我建议不要使用警报,只需在屏幕上设置动画即可显示您想要的内容,因为警报具有特定用途。它听起来比听起来容易得多。