Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

ios6 - UIAlertView with textfield and three buttons issue in ios 6

     UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Enter Student Name"        message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Save", @"Save and Add", nil];
                alert.tag = 1;
                alert.transform=CGAffineTransformMakeScale(1.0, 0.75);
                alert.alertViewStyle=UIAlertViewStylePlainTextInput;
                [alert show];

-(void)willPresentAlertView:(UIAlertView *)alertView {

    if (alertView.tag == 1) {


        for (UIView *view in alertView.subviews) {
            if ([view isKindOfClass:[UITextField class]]||
                [view isKindOfClass:[UIButton class]] || view.frame.size.height==31) {
                CGRect rect=view.frame;
                rect.origin.y += 65;
                view.frame = rect;
            }
        }

    }


}

As i am showing alertview with textfield and three buttons its working fine in ios 7 but not in ios 6 . have a look at both ios images -- > enter image description here

enter image description here

as you all can see the alertview of ios 6 is disturbed ... but i am not getting what i am doing wrong there .

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...