2013-04-13 78 views
0

我是新來的編程世界,但我正在開發一個應用程序。我有代碼設置,以便需要密碼,但是我希望它進入我的下一個要拍照的視圖。如果這是一個愚蠢的問題,我很抱歉,但我需要幫助。切換到另一個視圖,IOS

TestViewController.m文件

#import "TestViewController.h" 

@interface TestViewController() 

@end 
@implementation TestViewController 


- (IBAction)enterpassword 
{ 
    NSString *passwordString = [NSString stringWithFormat:@"1234"]; 

    if ([passwordfield.text isEqualToString:passwordString]) { 
     // Password is correct 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Correct Password" message:@"Password is Correct." delegate:self cancelButtonTitle:@"Enter" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
    } 
    else { 
     // Password is incorrect 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Incorrect Password" message:@"Password is Incorrect." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 

    } 

} 
- (void)viewDidLoad 

{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

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


@end 

@implementation PhotoAppViewController 
@synthesize imageView,choosePhotoBtn, takePhotoBtn; 

-(IBAction) getPhoto:(id) sender { 
    UIImagePickerController * picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 

    if((UIButton *) sender == choosePhotoBtn) { 
     picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
    } else { 
     picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    } 

    [self presentModalViewController:picker animated:YES]; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    [picker dismissModalViewControllerAnimated:YES]; 
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
} 

/* 
// The designated initializer. Override to perform setup that is required before the view is loaded. 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { 
// Custom initialization 
} 
return self; 
} 
*/ 

/* 
// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView { 
} 
*/ 


/* 
// 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 { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 
@end 
+1

你的實際問題是什麼? – sosborn

+0

請刪除多餘的代碼並專注於有問題的代碼,以便人們可以更輕鬆地幫助您。 –

回答

1

您需要創建視圖控制器,然後推動它,或者你可以有模式出示。

這樣的:

if ([passwordfield.text isEqualToString:passwordString]) { 
     // Password is correct 

    PhotoAppViewController *viewController = [[[PhotoAppViewController alloc] init] autorelease]; 
     [self pushViewController:PhotoAppViewController animated:YES]; 


    } 
    else { 
     // Password is incorrect 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Incorrect Password" message:@"Password is Incorrect." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 

你並不真的需要把一個警報說密碼是正確的......只是有它的工作。

+0

好的,謝謝你,現在更有意義。謝謝你幫助noob – Legitix

+0

樂意幫忙。我從StackOverflow獲得了很多幫助 – HalR

相關問題