UIAlertView with textfield and three buttons issue in ios 6

后端 未结 4 1670
旧巷少年郎
旧巷少年郎 2020-12-17 05:45
     UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@\"Enter Student Name\"        message:nil delegate:self cancelButtonTitle:@\"Cancel\" otherButtonTitles         


        
相关标签:
4条回答
  • 2020-12-17 06:13

    I tried it here as well and it seems the style "UIAlertViewStylePlainTextInput" doesn't go well with 3 or more buttons in the UIAlertView.

    your issue seems to be directly related to this:
    iOS5: Has somebody managed to fix UIAlertView with three buttons and textfield (UIAlertViewStylePlainTextInput)?


    It it won't be advisable to mess around with UIAlertView's view hierarchy (since some state App Store rejections)
    refer: How to Move buttons down in UIAlertView

    You can create your own custom alertView:
    http://iosdevtricks.blogspot.in/2013/04/creating-custom-alert-view-for-iphone.html

    or use a premade one, something like:
    https://github.com/TomSwift/TSAlertView

    if you still want to risk it, then go with what Kalpesh has suggested here (but i won't recommend it)

    0 讨论(0)
  • 2020-12-17 06:18

    In stead of messing with UIAlertView, you should use a custom presented (or a modal) view. Apple also doesn't like you to mess up with UIAlertView.

    So, my (and also the best) suggestion for you is to go with a custom presented (or a modal) view which is also a correct approach in your case also.

    0 讨论(0)
  • 2020-12-17 06:19

    Try this code

      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Enter Student Name"
                                                    message:@""
                                                   delegate:self
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:@"Save",@"Save & Add",nil];
    
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    [alert show];
    
    
    
    -(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)];
       }
    
    }
    

    Check for ios 6 image

    enter image description here

    EDIT

    For rotation problem use this code

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    if (UIInterfaceOrientationPortrait == UIInterfaceOrientationIsPortrait(fromInterfaceOrientation))
    {
               [alert setFrame:CGRectMake(100, 10, 286, 320)];
        NSArray *subviewArray = [alert subviews];
        UILabel *messageLB = (UILabel *)[subviewArray objectAtIndex:2];
        [messageLB setFrame:CGRectMake(10, 46, 260, 20)];
        UIButton *cancelBT = (UIButton *)[subviewArray objectAtIndex:3];
        [cancelBT setFrame:CGRectMake(10, 125, 260, 42)];
        UIButton *okBT = (UIButton *)[subviewArray objectAtIndex:4];
        [okBT setFrame:CGRectMake(10, 170, 260, 42)];
        UIButton *searchBT = (UIButton *)[subviewArray objectAtIndex:5];
        [searchBT setFrame:CGRectMake(10, 220, 260, 42)];
        UITextField *plateTF = (UITextField *)[subviewArray objectAtIndex:6];
        [plateTF setFrame:CGRectMake(10, 80, 266, 50)];
        UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
        [placeTF setFrame:CGRectMake(15, 70, 256, 50)];
    
      
    }
    else{
       
        [alert setFrame:CGRectMake(17, 30, 286, 280)];
        NSArray *subviewArray = [alert subviews];
        UILabel *messageLB = (UILabel *)[subviewArray objectAtIndex:2];
        [messageLB setFrame:CGRectMake(10, 46, 260, 20)];
        UIButton *cancelBT = (UIButton *)[subviewArray objectAtIndex:3];
        [cancelBT setFrame:CGRectMake(10, 125, 260, 42)];
        UIButton *okBT = (UIButton *)[subviewArray objectAtIndex:4];
        [okBT setFrame:CGRectMake(10, 170, 260, 42)];
        UIButton *searchBT = (UIButton *)[subviewArray objectAtIndex:5];
        [searchBT setFrame:CGRectMake(10, 220, 260, 42)];
        UITextField *plateTF = (UITextField *)[subviewArray objectAtIndex:6];
        [plateTF setFrame:CGRectMake(10, 80, 266, 50)];
        UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
        [placeTF setFrame:CGRectMake(15, 70, 256, 50)];
    
    }
    }
    
    0 讨论(0)
  • 2020-12-17 06:32

    What you are doing wrong is you're trying to customize UIAlertView and put subviews into it. Apple generally dislikes and prohibits this approach. What you can try to do is the following:

    1. You can try custom alert-view 'replication' like this one

    2. Write your own 'replication' of alert-view that will fit your needs and work the same on both iOS6/7.

    0 讨论(0)
提交回复
热议问题