我的UIAlertView文本字段使用iOS6时遇到问题。 文本字段一直移到顶部。当我使用iOS7时,文本字段位于正确的位置。 有人能帮我吗?这是代码:
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Item?"
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Add another", @"Done",nil];
[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeWords;
[message show];
文本字段显示在标题文本上(此处:项目?)
答案 0 :(得分:1)
实际上,这可以通过检测系统版本手动修复。以下是在此post
中执行此操作的正确方法答案 1 :(得分:1)
-(void)willPresentAlertView:(UIAlertView *)alertView {
if ([[[UIDevice currentDevice] systemVersion] floatValue] <7)
{
[alertView setFrame:CGRectMake(17, 30, 286, 280)];
NSArray *subviewArray = [alertView subviews];
UILabel *message = (UILabel *)[subviewArray objectAtIndex:2];
[message setFrame:CGRectMake(10, 46, 260, 20)];
UIButton *cancelbutton = (UIButton *)[subviewArray objectAtIndex:3];
[cancelbutton setFrame:CGRectMake(10, 125, 260, 42)];
UIButton *savebutton = (UIButton *)[subviewArray objectAtIndex:4];
[savebutton setFrame:CGRectMake(10, 170, 260, 42)];
UIButton *saveAddbutton = (UIButton *)[subviewArray objectAtIndex:5];
[saveAddbutton setFrame:CGRectMake(10, 220, 260, 42)];
UITextField *textfield = (UITextField *)[subviewArray objectAtIndex:6];
[textfield setFrame:CGRectMake(10, 80, 266, 50)];
UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
[placeTF setFrame:CGRectMake(15, 70, 256, 50)];
}
}
答案 2 :(得分:0)
试试这段代码,它会起作用。
- (IBAction)showAlert:(id)sender
{
UIAlertView *alertView = [[UIAlertView alloc] init];
alertView.delegate = self;
alertView.title = @"Item?";
alertView.message = nil;
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView addButtonWithTitle:@"Cancel"];
[alertView addButtonWithTitle:@"Add another"];
[alertView addButtonWithTitle:@"Done"];
[alertView show];
}