单例模式代码如下:
#import "TRclas.h"
static TRclas *share = nil;
@implementation TRclas
+(TRclas *)defaultNum{
if (!share)
{
share=[[TRclas alloc]init];
}
return share;
}
@end
.h文件代码
#import <Foundation/Foundation.h>
@interface TRclas : NSObject
@property(nonatomic ,assign)NSUInteger num;
+(TRclas *)defaultNum;
@end
#import "TRAViewController.h"
#import "TRBViewController.h"
#import "TRclas.h"
@interface TRAViewController ()
@property (weak, nonatomic) IBOutlet UIStepper *stepper;
@property(nonatomic,strong)TRBViewController *svc;
@end
@implementation TRAViewController
- (IBAction)btnA:(UIButton *)sender {
[TRclas defaultNum].num = (int)self.stepper.value;
self.svc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentViewController:self.svc animated:YES completion:nil];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.stepper.value=[TRclas defaultNum].num;
}