所以我有两节课。当按下保存按钮时,它会将值从self.screen.text
byaddItem
方法传递到totalArray
类 2。如果我尝试NSLog
在@implementation
ofaddItem
方法中,那么它将给出正确的输出,但如果我在 中执行viewDidLoad
,则输出为空。如何永久保存从 class1 传递到 class2 属性的值?谢谢你。UITableViewController 子类中的 class2
1 类@interface
//class1.h
#import class2.h
@interface class1 : superclass {
}
- (IBAction)buttonSave:(id)sender;
Class1 @implementation
//class1.m
@interface class1 ()
@end
@implementation class1 {
}
- (IBAction)buttonSave:(id)sender {
class2 *Obj = [[class2 alloc] init];
[Obj addItem:self.screen.text];
}
和 class2 @interface
//class2.h
#import class2.h
@interface {
}
@property (strong, nonatomic) NSMutableArray *totalArray;
类 2 @实现
@interface class2 ()
@end
@implementation {
}
- (void) addItem:(id)item {
self.totalArray = [[NSMutableArray alloc] init]; //alloc & init
[self.totalArray addObject:item]; //add object to the total array
// NSLog(@"%@", self.totalArray); If I NSLog in within this method then everything works as expected.
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%@", self.totalArray); //But in here the output is null. ???
}