我会创建一个类来保存这些值。然后在视图控制器之间传递这个对象。
像这样的东西:
接口文件:
//
// MyObject.h
// SOObjectPassing
//
// Created by Wilson, LJ on 11/15/12.
// Copyright (c) 2012 Arkansas Children's Hospital. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface MyObject : NSObject {
int shours;
int sminutes;
int sseconds;
int srecharge;
bool change;
}
@property (nonatomic, assign) int shours;
@property (nonatomic, assign) int sminutes;
@property (nonatomic, assign) int sseconds;
@property (nonatomic, assign) int srecharge;
@property (nonatomic, assign) BOOL change;
-(id) initWithHours:(int)hours
minutes:(int)minutes
seconds:(int)seconds
recharge:(int)recharge
changed:(BOOL)changed;
@end
实现文件:
//
// MyObject.m
// SOObjectPassing
//
// Created by Wilson, LJ on 11/15/12.
// Copyright (c) 2012 Arkansas Children's Hospital. All rights reserved.
//
#import "MyObject.h"
@implementation MyObject
@synthesize shours = _shours;
@synthesize sminutes = _sminutes;
@synthesize sseconds = _sseconds;
@synthesize srecharge = _srecharge;
@synthesize change = _change;
-(id) initWithHours:(int)hours
minutes:(int)minutes
seconds:(int)seconds
recharge:(int)recharge
changed:(BOOL)changed {
if ((self = [super init])) {
_shours = hours;
_sminutes = minutes;
_sseconds = seconds;
_srecharge = recharge;
_change = changed;
}
return self;
}
@end
并像这样实例化您的对象:
MyObject *myObject = [[MyObject alloc] initWithHours:2
minutes:3
seconds:4
recharge:1
changed:NO];
然后只需将整个对象传递给您的其他 VC。
这是说明这一点的示例项目。