Can't segue from UICollectionReusableView

327 views Asked by At

I have UICollectionView and Header.I have textfield and image.I did try push segue working fine.But I need to call segue! Any help will be appreciate

Header.h

@interface HeaderRV : UICollectionReusableView
@property (weak, nonatomic) IBOutlet UITextField *searchField;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
- (IBAction)backButton:(id)sender;


@end

Header.m

@implementation HeaderRV

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    // Initialization code
}
return self;
}
- (IBAction)backButton:(id)sender {

if ([self.searchField isEditing]) {
    [self.searchField resignFirstResponder];
}
else{
    //segue need to be here
}

}

@end
1

There are 1 answers

0
Wei On

I had the same problem as you do. It's actually quite tricky because you can have done "perform segue in collectionHeaderView" perfectly in an empty project(I tried). I found the key to this problem is your RootVC of navigation controller isn't the initial VC of the app.
You can get around this by adding the lines below in your .m file that presents the rootVC of navigation controller.

- (IBAction)next:(id)sender {
[theRootVCinNavigationController] *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"[your identifier]"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[theRootVCinNavigationController]];
[self presentViewController:navigationController animated:YES completion:nil];
}

References:

  1. How to add an UINavigationController to an UIViewController presented as Modal
  2. https://developer.apple.com/Library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html (search for "Creating a navigation interface")