模态视图未在设备上显示

时间:2011-03-07 06:45:18

标签: iphone device modal-view

我在iphone应用程序中使用模态视图。问题是视图正在模拟器上工作但是当我在设备上安装时,而不是模态视图,而是显示一个白色的空白屏幕。有没有人遇到过这个问题?我该如何解决这个问题?以下是代码。

#import "ResetPWD.h"
#import "WebServiceController.h"
#import "ProductAppDelegate.h"

@implementation ResetPWD

@synthesize oldPWD;
@synthesize newPWD;
@synthesize newPWD2;
@synthesize password1;
@synthesize password2;




-(IBAction)done:(id)sender {


    NSString *pwd = oldPWD.text;
    NSString *pwd1 = newPWD.text;
    NSString *pwd2 = newPWD2.text;



    if(!self.oldPWD.text )
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Enter Old Password."
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];   
        [alert release];    
        return;
    }

    if(!self.newPWD.text )
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Enter New Password."
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];   
        [alert release];    
        return;
    }


    if ([pwd1 length]<6) {

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"New password should be atleast 6 characters long" delegate:self   cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];

        return;


    }



    if (![pwd1 isEqualToString:pwd2]) {



        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Passwords do not match" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];

        return;         
    }

    password1 = pwd;
    password2 = pwd1;



    NSMutableArray *data = [[NSMutableArray alloc]init];



    [data addObject:password1];
    [data addObject:password2];


    WebServiceController *webCall = [[WebServiceController alloc]init];

    NSDictionary *dict = [webCall resetPWD:data];


    NSString * nVal = [dict objectForKey:@"ErrorCode"];
    NSString *errorDesc = [dict objectForKey:@"ErrorType"];
    NSString *errorString = [dict objectForKey:@"ErrorString"];


    int n=[nVal integerValue];

    if(n>=3)
    {
        errorString=[[NSString alloc]initWithFormat:@"%@\nProceed to broker registration.",errorString];
    }

    UIAlertView *successAlert=[[UIAlertView alloc]initWithTitle:errorDesc message:errorString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

    [successAlert show];
    [successAlert release];


    [self.parentViewController dismissModalViewControllerAnimated:YES];




}


-(IBAction)cancel:(id)sender {

    [self.parentViewController dismissModalViewControllerAnimated:YES];

}



- (void)textFieldDidBeginEditing:(UITextField *)textField {




    CGRect textFieldRect =
    [self.view.window convertRect:textField.bounds fromView:textField];
    CGRect viewRect =
    [self.view.window convertRect:self.view.bounds fromView:self.view];
    CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
    //if (textField == usernameField) 
    //  midline+=20;

    CGFloat numerator = midline - viewRect.origin.y - MINIMUM_SCROLL_FRACTION * viewRect.size.height;
    CGFloat denominator =   (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION) * viewRect.size.height;
    CGFloat heightFraction = numerator / denominator;
    if (heightFraction < 0.0)
    {
        heightFraction = 0.0;
    }
    else if (heightFraction > 1.0)
    {
        heightFraction = 1.0;
    }
    animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
    CGRect viewFrame = self.view.frame;
    viewFrame.origin.y -= animatedDistance;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];

    [self.view setFrame:viewFrame];

    [UIView commitAnimations];


}

- (void)textFieldDidEndEditing:(UITextField *)textField
{



    CGRect viewFrame = self.view.frame;
    viewFrame.origin.y += animatedDistance;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];

    [self.view setFrame:viewFrame];

    [UIView commitAnimations];

}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    // the user pressed the "Done" button, so dismiss the keyboard
    [textField resignFirstResponder];
    return NO;
}





// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end

此视图未在设备上显示,但在模拟器上显示。设计也是在xib文件中完成的。

1 个答案:

答案 0 :(得分:0)

在实例化我的视图时,我需要使用initWithNibName。之后开始工作