iPhone monotouch中可选项目的警报视图

时间:2013-06-29 05:27:25

标签: iphone ios ipad xamarin.ios uialertview

在android中我们可以有一个警告对话框,其中包含一些项目列表,如下图所示:

enter image description here

但是对于iPhone案例,我们如何创建这样的警报视图?

2 个答案:

答案 0 :(得分:1)

您需要使用座席名称和电话属性创建MyCustomAlertViewController。创建xib。之后写这样:

- (void) alertForAgentName: (NSString*) anAgentName agentPhoneNumber: (NSString*) anAgentPhoneNumber
{
    MyCustomAlertViewController* modalViewController =
        [[MyCustomAlertViewController alloc] initWithNibName: @"MyCustomAlertViewController" bundle:nil];

    modalViewController.agentName = anAgentName;
    modalViewController.agentPhoneNumber = anAgentPhoneNumber;

    UINavigationController *modalViewNavController =
        [[UINavigationController alloc]
        initWithRootViewController: modalViewController];

    [self.navigationController presentModalViewController:
        modalViewNavController animated:YES];
    // If MRC
    [modalViewNavController release];
}

对于dismiss对话框,你需要像这样调用它(它在MyCustomAlertViewController类中):

- (IBAction) dismissModalView:(id)sender
{
    [self.parentViewController dismissModalViewControllerAnimated:NO];
}

答案 1 :(得分:0)

您可以像这样创建一个警告

UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
UILabel *labelone = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
labelone.text=@"label1";
[labelone setBackgroundColor:[UIColor clearColor]];
[labelone setTextAlignment:UITextAlignmentLeft];

UILabel *labeltwo = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
labeltwo.text=@"label2";
[labeltwo setBackgroundColor:[UIColor clearColor]];
[labeltwo setTextAlignment:UITextAlignmentLeft];

UILabel *labelthree = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
labelthree.text=@"label3";
[labelthree setBackgroundColor:[UIColor clearColor]];
[labelthree setTextAlignment:UITextAlignmentLeft];

[alert addSubview:labelone];
[alert addSubview:labeltwo];
[alert addSubview:labelthree];

[alert setDelegate:self];
[alert show];
[alert release];

如果您想调整alertview的框架大小,可以使用

- (void)willPresentAlertView:(UIAlertView *)alertView {
alertView.frame = CGRectMake(20.f, 200.f, 280.f, 150.f);
NSArray *subViewArray = alertView.subviews;
for(int x=0;x<[subViewArray count];x++){
    if([[[subViewArray objectAtIndex:x] class] isSubclassOfClass:[UILabel class]])
    {
        UILabel *label = [subViewArray objectAtIndex:x];
        label.textAlignment = UITextAlignmentLeft;
    }
}

}