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 回答