设备上未显示模态视图

发布于 2024-10-21 00:38:58 字数 5854 浏览 0 评论 0原文

我在 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 文件中完成的。

I am using modal views in my iphone application. The problem is that the views are working on the simulator but when I am installing it on the device, instead of the modal views,instead it shows a white blank screen . Anyone encountered this problem before? How do i solve this? The following is the code.

#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

this view is not showing on the device, but showing on the simulator. also the designing is done in a xib file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你曾走过我的故事 2024-10-28 00:38:58

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

While instantiating my views I need to use initWithNibName. Started working after that

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文