Bedingter Viewwechsel (Storyboard)

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Bedingter Viewwechsel (Storyboard)

    Ich habe im Rahmen meiner Hochschularbeit mit einem iPhone Projekt angefangen. Bin absoluter Neuanfänger und habe mich bis jetzt durch unterschiedliche Dokumentationen durch gelesen. Hänge aber leider hier fest. Kann mir mal jemand weiter helfen.Ich habe folgenden Code:

    Quellcode

    1. //
    2. // ViewController.m
    3. // JanJSon2
    4. //
    5. // Created by Emre on 04.06.12.
    6. // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
    7. //
    8. #import "ViewController.h"
    9. #import "JSONKit.h"
    10. #import "SBJSON.h"
    11. #import "JSonSchnittstelle.h"
    12. #import "SearchViewController.h"
    13. @implementation ViewController
    14. @synthesize idField;
    15. @synthesize passwordField;
    16. @synthesize statusLabel;
    17. @synthesize activityIndicator;
    18. @synthesize logiButton;
    19. - (void) showData:(NSDictionary *)data{
    20. //NSLog(@"DataString: %@ ", data);
    21. NSLog(@"Test2");
    22. activityIndicator.hidden = TRUE;
    23. [activityIndicator stopAnimating];
    24. BOOL value = [[data valueForKey:@"authOk"]boolValue];
    25. NSLog(@"%@", value ? @"YES" : @"NO");
    26. if (value){
    27. [self performSegueWithIdentifier:@"toMainScreen" sender:self];
    28. }else {
    29. UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Fehler" message:(NSLocalizedString(@"LoginFailed", @"")) delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    30. statusLabel.text = @"Id/Password is wrong";
    31. [alert show];
    32. [idField setUserInteractionEnabled:YES];
    33. [passwordField setUserInteractionEnabled:YES];
    34. }
    35. }
    36. -(BOOL)textFieldShouldReturn:(UITextField *)textField{
    37. NSLog(@"Next_Taste");
    38. if(textField == idField) {
    39. [passwordField becomeFirstResponder];
    40. }
    41. else
    42. [textField resignFirstResponder];
    43. return YES;
    44. }
    45. - (IBAction)sendRequest:(id)sender {
    46. [idField setUserInteractionEnabled:NO];
    47. [passwordField setUserInteractionEnabled:NO];
    48. //[logiButton setTitle:@"Anmeldung erfolgt" forState:UIControlStateNormal];
    49. [sender setTitle:@"Anmeldung erfolgt" forState:UIControlStateNormal];
    50. activityIndicator.hidden = FALSE;
    51. [activityIndicator startAnimating];
    52. loginId = idField.text;
    53. loginPassword = passwordField.text;
    54. JSonSchnittstelle *JSonSchnittstellenString = [[JSonSchnittstelle alloc]init];
    55. [JSonSchnittstellenString setDelegate:self];
    56. NSDictionary *JSonData1 = [JSonSchnittstellenString buildRequestString:loginId withData:loginPassword];
    57. //NSDictionary *JSonData = [JSonSchnittstellenString loginRequest:JSonData1];
    58. [JSonSchnittstellenString sendRequest:JSonData1];
    59. }
    60. - (void)viewDidLoad
    61. {
    62. [super viewDidLoad];
    63. // Do any additional setup after loading the view, typically from a nib.
    64. //delegate = self;
    65. activityIndicator.hidden = YES;
    66. }
    67. - (void)viewDidUnload
    68. {
    69. //[self setIdFiled:nil];
    70. //[self setIdPassword:nil];
    71. [super viewDidUnload];
    72. // Release any retained subviews of the main view.
    73. }
    74. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    75. {
    76. return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    77. }
    78. @end
    Alles anzeigen


    Dies ist mein LoginScreen, in showData kommen meine Daten an, die per Request (eigene Delegate) zuvor gesendet wurden. Ich möchte anhand der Abfrage nun zur nächsten View wechseln. Wie geht das !? Was muss ich machen ?!

    Ich habe den Wechsel zwar im Storyboard mit einer Segue gemacht aber der Wechsel findet immer statt, egal ob die Bedingung stimmt oder nicht.
  • Du holst Dir aus dem Storyboard den gewünschten Viewcontroller und zeigst beispw. modal ihn an:

    Quellcode

    1. id theController = [self.storyboard instantiateViewControllerWithIdentifier:@"..."];
    2. [theControler setIrgendWas:...];
    3. [self presentViewController:theController animated:YES completion:NULL];
    „Meine Komplikation hatte eine Komplikation.“