UIAlertView in ipad4.2

Discussion in 'iOS Programming' started by AbhishekApple, Jan 10, 2011.

  1. macrumors member

    Aug 5, 2010
    I had added a textfield in alertview which displayed properly in 3.2 but same code(coordinates) is creating problem in 4.2

    	txtFilenm = [[UITextField alloc]initWithFrame:CGRectMake(15, 70, 255, 30)];
    	txtFilenm.placeholder = @"Catalog Name";
    	txtFilenm.borderStyle = UITextBorderStyleRoundedRect;
    	txtFilenm.delegate = self;
    	UIAlertView *alert = [[UIAlertView alloc] 
    						  initWithTitle: @"Enter catalog name" 
    						  otherButtonTitles:@"Button1",@"Button2", nil];
    	alert.tag =11;
    	[COLOR="red"][alert addSubview:txtFilenm];[/COLOR]
    	[alert show];
    	[alert release];
    The textfield fits in the space created by newline ("\n\n\n") in 3.2 but in 4.2 the space is not created when i add the textfield.... the Button1 comes jst below the alerttitle then the textfield overlapping some part of Button1 n followed by other buttons ....

    If i don't add the textfield in alert view the space is created!!!!!!
  2. thread starter macrumors member

    Aug 5, 2010
    no one came across this issue.....
    If u didn't get the issue please jst copy the code and execute it in 3.2 & 4.2 iossdk for ipad simulator..
  3. macrumors newbie

    Aug 11, 2010
    Jalisco, México
    Is better solutions subclass AlertView

    Maybe a better solution is subclass UIAlertView.

    @implementation Alert
    -(void)setFrame:(CGRect)nFrame {
    	CGFloat newHeightNeeded = 250;
    	[super setFrame:CGRectMake(nFrame.origin.x, nFrame.origin.y, nFrame.size.width, newHeightNeeded)];
    -(void)layoutSubviews {
    	CGFloat newHeightNeeded = 250;
            CGFloat originalHeight = 120;
    	for (UIView *tempo in self.subviews) {
    		if ([[[tempo class] description] isEqualToString:@"UIThreePartButton"]) {
    			tempo.frame = CGRectMake(tempo.frame.origin.x, tempo.bounds.size.height + (newHeightNeeded-originalHeight), tempo.frame.size.width, tempo.frame.size.height);
    Sorry mi english is bad...

Share This Page