我希望你能帮助我。
我需要一个变量,当我点击View1上的任何按钮(View 1有6个按钮)时,变量应该有任何值,例如1-6。然后在视图二中,我将检查变量的值。
答案 0 :(得分: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
希望你能得到它,你可以向我寻求任何帮助,谢谢:)