2 mapmapm MapMapM 于 2013.07.01 14:33 提问

iPhone-带选项的警报视图

Android中可以有带选项的警报对话框,如下图:

CSDN移动问答

但是iPhone应该怎么实现类似的呢?

2个回答

gaoXxxing
gaoXxxing   2013.07.01 15:51
已采纳

创建有代理名称和属性的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];
}

解除对话框时进行调用:

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

创建警告:

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];

调整警告框的框架尺寸:

- (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;
    }
}
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!