确认后退导航

时间:2013-10-13 07:18:25

标签: iphone objective-c ios7 xcode5

我只想确认其中一个视图的后退导航。特定视图是UICollectionViewController。我知道我在if语句中的确切编码是对的。我不太清楚怎么做。填写空白给我?

CollectionViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    BOOL isThisViewACollectionView = YES;

}

-(void) viewWillDisappear:(BOOL)animated {
    if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
        // back button was pressed.  We know this is true because self is no longer
        // in the navigation stack.
        if (isThisViewACollectionView) {
            UIAlertView *cameraAlertView = [[UIAlertView alloc] initWithTitle:@"Camera Not Available" message:@"The camera feature isn't available on your device." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
            [cameraAlertView show];
        }
    }else{
        [super viewWillDisappear:animated];
    }
}

1 个答案:

答案 0 :(得分:1)

逻辑存在问题, 您已经删除了viewcontroller

时调用以下语句
   if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {

    }

所以一个更好的解决方案是将值保存在“上面(之前)”viewWillDisappear,它知道viewcontroller是否是uicollectionView(让我们说一个BOOL) 并假设此值为true,提醒用户(填写丢失的代码)。