无法从 UI 中分离可重用视图



我有UICollectionView和Header.I 有textfield和image。我确实尝试了推送 segue 工作正常。但是我需要打电话给塞格!任何帮助将不胜感激

标题.h

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

@end

标题.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

我和你有同样的问题。这实际上非常棘手,因为您可以在一个空项目中完美地完成"在collectionHeaderView中执行segue"(我试过了)。我发现这个问题的关键是导航控制器的 RootVC 不是应用程序的初始 VC
您可以通过在 .m 文件中添加以下行来解决此问题,该文件表示导航控制器的 rootVC。

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

引用:

  1. 如何将 UINavigationController 添加到显示为模态
    的 UIViewController
  2. https://developer.apple.com/Library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html(搜索"创建导航界面")

最新更新