ViewdidAppear在第一个VC之前触发第二个VC

时间:2015-02-07 04:27:02

标签: ios objective-c

2015-02-06 23:23:35.976 a[47551:2124298] second view did load
2015-02-06 23:23:35.978 a[47551:2124298] first view did load
2015-02-06 23:23:36.060 a[47551:2124298] second view did appear
2015-02-06 23:23:36.062 a[47551:2124298] first view did appear

以上描述了我的问题。我想在第二个视图出现后才开始做事,但是一旦我启动应用程序,我就会先做所有事件。

第一个观点:

@interface AddViewController ()

@end

@implementation AddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"first view did load");
    // Do any additional setup after loading the view.
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSLog(@"first view did appear");
}

- (IBAction)addBtnPressed:(id)sender {
    NSLog(@"add Btn pressed");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    ViewController *destVC = [segue destinationViewController];
    destVC.destStation = self.destField.text;
}

第二种观点:

- (void)viewDidLoad {
[super viewDidLoad];

NSLog(@"second view did load");

manager = [[ CLLocationManager alloc] init];
geocoder = [[ CLGeocoder alloc] init];

[manager requestWhenInUseAuthorization];

// [manager requestAlwaysAuthorization]; }

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    NSLog(@"second view did appear");

    manager.delegate = self;
    manager.desiredAccuracy = kCLLocationAccuracyBest;

    NSLog(@"setting destStation %@", self.destStation);
    self.destField.text = self.destStation;
    self.destStationLoc = [LocationCalc findDestStationLoc:self.destStation stationInfos:[StationDB database].stationInfos];
}

segue是从第一个VC的按钮连接的。 我做错了吗?

0 个答案:

没有答案