如何在选项卡之间切换并直接显示推送的视图控制器?

How to switch between tabs and directly show pushed view controller?

这是我的代码:

  VideoDetailViewController *VideoDetailVC = [self.storyboard instantiateViewControllerWithIdentifier:@"VideoDetailViewController"];

  UINavigationController * navigationController = (UINavigationController *) [[self tabBarController] selectedViewController];

  [self.tabBarController setSelectedIndex:0];

  [navigationController pushViewController:VideoDetailVC animated:YES];

我在tabbar的第二个索引中写这段代码。我想直接转到 Video Detail 屏幕,它是 tabbar 的零索引的子视图控制器。一切正常,但我看到的是:它显示了一个父视图控制器,它是标签栏的零索引。一秒钟后,它会推送到“视频详细信息”屏幕。我只是不想显示零索引。解决办法是什么?帮助将不胜感激。

已编辑:

#import "TWPhotoCollectionViewCell.h"

@implementation TWPhotoCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.imageView = [[UIImageView alloc] initWithFrame:self.bounds];
        self.imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        self.imageView.layer.borderColor = [UIColor blueColor].CGColor;
        [self.contentView addSubview:self.imageView];
    }
    return self;
}

- (void)setSelected:(BOOL)selected {
    [super setSelected:selected];

    self.imageView.layer.borderWidth = selected ? 2 : 0;
}

@end

替换下行

  [navigationController pushViewController:VideoDetailVC animated:YES];

  [navigationController pushViewController:VideoDetailVC animated:NO];

它可能会解决您的问题。