0

I hope you can help me.

I need a variable, which when I click on any button on View1 (View 1 have 6 Buttons) the Variable should have any value e.g. 1-6. Then in view two I will check the value of the Variable.

4

1 に答える 1

1

あなたの view2.h クラスは次のようになります

#import <UIKit/UIKit.h>

@interface ForgotPasswordViewController : UIViewController

@property (nonatomic, retain) NSString *strName;

@end

あなたの view2.m クラスは次のようになります

#import "ForgotPasswordViewController.h"

@interface ForgotPasswordViewController ()

@end

@implementation ForgotPasswordViewController

@synthesize strName;

#pragma mark -
#pragma mark - Init
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

#pragma mark -
#pragma mark - View LifeCycle
-(void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSLog(@"the value of name is %@",strName);
}

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

@end

あなたのview1.mクラスでは次のようにする必要があります

#import "ViewController.h"
#import "ForgotPasswordViewController.h"

@interface ViewController ()

@end

@implementation ViewController

#pragma mark -
#pragma mark - View LifeCycle
-(void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

    ForgotPasswordViewController *vcForgotPasswordViewController = [[ForgotPasswordViewController alloc] initWithNibName:@"ForgotPasswordViewController" bundle:nil];
    vcForgotPasswordViewController.strName = @"Dhaval";
    [self.navigationController pushViewController:vcForgotPasswordViewController animated:YES];
}

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

@end

それ以外の場合は、私に助けを求めることができます:)

于 2013-09-09T10:27:16.317 に答える