问题描述
解决方案
创建有代理名称和属性的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];
}
解决方案二:
创建警告:
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;
}
}
}
时间: 2024-12-21 21:25:20