簡體   English   中英

iOS導航下一個ViewController

[英]iOS Navigate Next ViewController

我有一個名為PlantingTreeVC的視圖控制器。 因為有兩種付款方式,即。 PaybyCreditCardPaybyCash 。如果用戶選擇PaybyCreditCard並單擊NextButton ,則應導航到PayPalVC或者如果用戶選擇PaybyCash並單擊NextButton ,則應導航到CustomerDetailsVC。 我該怎么做?

我的代碼如下:

PlantingTreeVC.h

#import "ViewController.h"

@interface PlantingTreeVC : ViewController {
    BOOL checked;
}
@property (weak, nonatomic) IBOutlet UIImageView *topStrip;
@property (weak, nonatomic) IBOutlet UIImageView *bgView;
@property (weak, nonatomic) IBOutlet UITextField *plantsNumber;
@property (weak, nonatomic) IBOutlet UIImageView *AddNamesBG;
@property (weak, nonatomic) IBOutlet UILabel *plantNameLbl;
@property (weak, nonatomic) IBOutlet UITextField *nametextField;
@property (weak, nonatomic) IBOutlet UILabel *commaTextLbl;
@property (weak, nonatomic) IBOutlet UILabel *getPlaqueLbl;

@property (weak, nonatomic) IBOutlet UIScrollView *plantScrollView;
@property (weak, nonatomic) IBOutlet UISwitch *Switch;

@property (weak, nonatomic) IBOutlet UIImageView *giveTreeView;
@property (weak, nonatomic) IBOutlet UISwitch *giveTreeIB;
@property (weak, nonatomic) IBOutlet UILabel *giveTreeLbl;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *emailLabel;
@property (weak, nonatomic) IBOutlet UILabel *phonenoLabel;
@property (weak, nonatomic) IBOutlet UITextField *friendnameTextField;
@property (weak, nonatomic) IBOutlet UITextField *emailTextField;
@property (weak, nonatomic) IBOutlet UITextField *phonenoTextField;
@property (weak, nonatomic) IBOutlet UILabel *totalAmountLabel;
@property (weak, nonatomic) IBOutlet UILabel *amountTextLbl;
@property (weak, nonatomic) IBOutlet UIImageView *paymentView;
@property (weak, nonatomic) IBOutlet UILabel *payByCardLbl;
@property (weak, nonatomic) IBOutlet UILabel *payByCashLbl;

@property (weak, nonatomic) IBOutlet UIButton *paybyCardIB;
@property (weak, nonatomic) IBOutlet UIButton *payByCashIB;
@property (weak, nonatomic) IBOutlet UIButton *backBtIB;
@property (weak, nonatomic) IBOutlet UIButton *nextBtIB;
- (IBAction)BackButton:(id)sender;
- (IBAction)NextButton:(id)sender;

- (IBAction)PayByCardButton:(id)sender;
- (IBAction)PayByCashButton:(id)sender;

- (IBAction)NamesSwitchController:(id)sender;

- (IBAction)GivethisTreeController:(id)sender;
@end

PlantingTreeVC.m

#import "PlantingTreeVC.h"

#import "PayPalVC.h"

@interface PlantingTreeVC ()



@end



@implementation PlantingTreeVC

@synthesize plantsNumber;

@synthesize AddNamesBG;

@synthesize Switch;

@synthesize plantNameLbl;

@synthesize nametextField;

@synthesize commaTextLbl;

@synthesize plantScrollView;

@synthesize bgView;

@synthesize topStrip;

@synthesize backBtIB;

@synthesize nextBtIB;



@synthesize giveTreeView;

@synthesize giveTreeIB;

@synthesize nameLabel;

@synthesize emailLabel;

@synthesize phonenoLabel;

@synthesize friendnameTextField;

@synthesize emailTextField;

@synthesize phonenoTextField;

@synthesize paybyCardIB;

@synthesize payByCashIB;



- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [self.view endEditing:YES];

    [super touchesBegan:touches withEvent:event];

}



- (void)viewDidLoad {

    [super viewDidLoad];

    [self.view sendSubviewToBack:bgView];

    [self.view bringSubviewToFront:topStrip];

    [self.view bringSubviewToFront:plantScrollView];

    [self.view bringSubviewToFront:backBtIB];

    [self.view bringSubviewToFront:nextBtIB];





    nametextField.backgroundColor = [UIColor clearColor];

    friendnameTextField.backgroundColor = [UIColor clearColor];

    emailTextField.backgroundColor = [UIColor clearColor];

    phonenoTextField.backgroundColor = [UIColor clearColor];

    plantNameLbl.hidden =YES;

    nametextField.hidden = YES;

    commaTextLbl.hidden=YES;



    nameLabel.hidden=YES;

    emailLabel.hidden =YES;

    phonenoLabel.hidden=YES;

    friendnameTextField.hidden=YES;

    emailTextField.hidden=YES;

    phonenoTextField.hidden=YES;



    checked=NO;





    [plantScrollView setScrollEnabled:YES];



    CGFloat scrollViewHeight = 0.0f;

    for (UIView* view in plantScrollView.subviews)

    {

        scrollViewHeight += view.frame.size.height;

    }

    [plantScrollView setContentSize:(CGSizeMake(300, 900))];

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

- (IBAction)BackButton:(id)sender {

}



- (IBAction)NextButton:(id)sender {

    NSLog(@"noofplants:%@",plantsNumber.text);

    NSLog(@"plant_names:%@",nametextField.text);

   // NSLog(@"name:%@",namet.text);

    //NSLog(@"email:%@",emailTextField.text);

   // NSLog(@"phone_number:%@",phonenoTextField.text);

    NSLog(@"friend_name:%@",friendnameTextField.text);

    NSLog(@"friend_email:%@",emailTextField.text);

    NSLog(@"f_phone_number:%@",phonenoTextField.text);

 //   NSLog(@"pickup_address:%@",passwordTextField.text);

 //   NSLog(@"purchase_date:%@",confirmTextField.text);

 //   NSLog(@"renewal_date:%@",passwordTextField.text);

   // NSLog(@"price:%@",);

    //NSLog(@"price:%@",payment_method_type.text);





    /* if ([self isValidEmail:[emailTextField text]] == 1) {



     UIAlertView* alertViewq = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Please enter Valid email" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

     [alertViewq show];

     } */



    if([plantsNumber.text isEqualToString:@""] || [nametextField.text isEqualToString:@""] || [friendnameTextField.text isEqualToString:@""] || [emailTextField.text isEqualToString:@""] || [phonenoTextField.text isEqualToString:@""])



    {

        UIAlertView* alertViewq = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Please enter all the details." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [alertViewq show];



    }

      else

    {

        NSString *post = [NSString stringWithFormat:@"&noofplants=%@&plant_names=%@&friend_name=%@&friend_email=%@&f_phone_number=%@",plantsNumber.text,nametextField.text,friendnameTextField.text,emailTextField.text,phonenoTextField.text];

        NSLog(@"post:%@",post);

        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

        NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];

        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

        [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://someurl.com/sample.php"]]];

        [request setHTTPMethod:@"POST"];

        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];

        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];

        [request setHTTPBody:postData];

        NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];



        if (theConnection)

        {

        }

        else

        {

            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Failed" message:@"Check your networking configuration." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [alertView show];

        }



    }

}



- (IBAction)PayByCardButton:(id)sender {

   }



- (IBAction)PayByCashButton:(id)sender {

    if (!checked) {

        [payByCashIB setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];

        checked=YES;

    }

    else if (payByCashIB){

        [payByCashIB setImage:[UIImage imageNamed:@"uncheckbox.png"] forState:UIControlStateNormal];

        checked=NO;

    }

//    

//      PayPalVC *PVC = [self.storyboard instantiateViewControllerWithIdentifier:@"PaymentScreen"];

//     [self presentViewController:PVC animated:YES completion:nil];

}



- (IBAction)NamesSwitchController:(id)sender {

    if (Switch.on) {



        self.AddNamesBG.frame = CGRectMake(5, 79, 288,156);

        plantNameLbl.hidden =NO;

        nametextField.hidden = NO;

        commaTextLbl.hidden=NO;

}



    else {

        self.AddNamesBG.frame = CGRectMake(5, 79, 288,61);

        plantNameLbl.hidden =YES;

        nametextField.hidden = YES;

        commaTextLbl.hidden=YES;

 }

}

- (IBAction)GivethisTreeController:(id)sender {

    if (giveTreeIB.on) {



        self.giveTreeView.frame = CGRectMake(5, 232, 288,210);

        nameLabel.hidden=NO;

        emailLabel.hidden =NO;

        phonenoLabel.hidden=NO;

        friendnameTextField.hidden=NO;

        emailTextField.hidden=NO;

        phonenoTextField.hidden=NO;

}



    else {

        self.giveTreeView.frame = CGRectMake(5, 232, 288,64);

        nameLabel.hidden=YES;

        emailLabel.hidden =YES;

        phonenoLabel.hidden=YES;

        friendnameTextField.hidden=YES;

        emailTextField.hidden=YES;

        phonenoTextField.hidden=YES;

    }

}

@end
@interface PlantingTreeVC ()
{
   PaybyCreditCard_BOOL,PaybyCash_BOOL
}
@end

  //Other code

- (IBAction)PayByCardButton:(id)sender{
    if(PaybyCreditCard_BOOL){
      PaybyCreditCard_BOOL=NO;
     }
     else{
      PaybyCreditCard_BOOL=YES;

    //Dont forget this check also
         if(PaybyCash_BOOL){
            PaybyCash_BOOL =NO;
          }


      }

  }

- (IBAction)PayByCashButton:(id)sender{
   if(PaybyCash_BOOL){
    PaybyCash_BOOL =NO;
     }
   else{
   PaybyCash_BOOL =YES;
 //Dont forget this check also

         if(PaybyCreditCard_BOOL){
             PaybyCreditCard_BOOL =NO;
          }
    }
  }

 - (IBAction)NextButton:(id)sender{
     if(PaybyCreditCard_BOOL){
     //go toPayPalVC
     }
    else if(PaybyCash_BOOL){

    //go toPayPalCash
    }
    else{
      }
  }

創建兩個布爾PaybyCreditCard_BOOL,PaybyCash_BOOL,默認將它們設置為NO。現在,當點擊按鈕時,它將切換為是和否。請參見上面的代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM