-1

我只想确认我拥有的其中一个视图的后退导航。具体的视图是一个 UICollectionViewController。我知道我在 if 语句中的确切编码不正确。我不太确定该怎么做。帮我填空?

集合视图控制器.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];
    }
}
4

1 回答 1

1

逻辑有问题,当您已经删除视图控制器时,会调用以下语句

   if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {

    }

因此,更好的解决方案是在“高于(之前)”viewWillDisappear 的某个位置保存一个值,它知道 viewcontroller 是否为 uicollectionView(比方说 BOOL),并假设该值是真实的,提醒用户(填写您丢失的代码)。

于 2013-10-13T09:02:46.733 回答