Hiren Prajapati
Hiren Prajapati

Reputation: 727

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.

EDITED:

#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

Upvotes: 0

Views: 44

Answers (1)

Ketan Parmar
Ketan Parmar

Reputation: 27428

Replace below line

  [navigationController pushViewController:VideoDetailVC animated:YES];

With

  [navigationController pushViewController:VideoDetailVC animated:NO];

It may solve your issue.

Upvotes: 1

Related Questions