Hiren Prajapati Hiren Prajapati - 4 months ago 8x
iOS Question

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

This is my code:

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

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

[self.tabBarController setSelectedIndex:0];

[navigationController pushViewController:VideoDetailVC animated:YES];

I am writing this code in tabbar's second index. I want to directly go to the Video Detail screen, which is child view controller of tabbar's zero index. Everything works fine but what I see is: it shows a parent view controller which is tabbar's zero index. After a second it pushes to the Video Detail screen. I just don't want to show the zero index. What is the solution? Help will be appreciated.


#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;



Replace below line

  [navigationController pushViewController:VideoDetailVC animated:YES];


  [navigationController pushViewController:VideoDetailVC animated:NO];

It may solve your issue.