下面是我的代码:
SecondViewController.h:
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
-(IBAction) UploadMethod:(id)sender;
@property (nonatomic) NSInteger numberOfImagesUploaded ;
@end
第二视图控制器.m:
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
@synthesize numberOfImagesUploaded ;
NSInteger numberOfImagesUploaded = 1 ;
-(IBAction)UploadMethod:(id)sender {
// Upload method (not important)
numberOfImagesUploaded ++ ;
}
第三视图控制器.m:
#import "ThirdViewController.h"
#import "SecondViewController.h"
@interface ThirdViewController ()
@end
@implementation ThirdViewController
- (void)viewDidLoad {
[super viewDidLoad];
SecondViewController *useSecondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] ;
NSInteger number = useSecondView.numberOfImagesUploaded ;
}
我的问题是在线
NSInteger number = useSecondView.numberOfImagesUploaded ;
虽然数字总是返回 0,但当我在 SecondViewController 中测试 numberOfImagesUploaded 的内容时,它是一个不为零的整数。那么,我的方法是否错误地从其他 viewController 获取变量?或者我无法从另一个 viewController 访问方法体内的变量?