我正在制作一个程序,当按下一个按钮时,程序将启动,然后弹出SecondView(在秒视图内,有一个标签字段需要从Main ViewController连续加载/更新过程值)。
我的问题是:
MainViewController
#import "ViewController.h"
#import "SencondViewController.h"
@implementation ViewController
@synthesize passValue;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
// Update the view, if already loaded.
}
- (IBAction)btStart:(id)sender {
@autoreleasepool{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
for (int i = 0; i < 100; i++) {
[NSThread sleepForTimeInterval:0.05];
dispatch_async(dispatch_get_main_queue(), ^(void) {
self->passValue = [@(i) stringValue];
[self performSegueWithIdentifier:@"LoadingView" sender:nil];
});
}
});
}
}
- (IBAction)btClose:(id)sender {
}
- (void)prepareForSegue:(NSStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"LoadingView"]) {
SencondViewController * secondVC = segue.destinationController;
secondVC.progressValue = passValue;
}
}
@end
在SeconViewController中
#import "SencondViewController.h"
@interface SencondViewController ()
@end
@implementation SencondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
@try{
_textProcess.stringValue = _progressValue;}@catch(NSException *ex){};
}
@end