从自定义 UIPopOver 问题推送新的 UIViewController
Posted
技术标签:
【中文标题】从自定义 UIPopOver 问题推送新的 UIViewController【英文标题】:Pushing new UIViewController from custom UIPopOver issue 【发布时间】:2015-04-03 10:57:37 【问题描述】:您好,我正在使用这个library 来显示我的 PopOver,其中包含带有 searchBar 的 tableView。
问题是一个用户尝试从 tableView 中选择行而不是关闭 popOver 并在孔屏幕中显示选定的行我得到了这个:
。
我尝试使用[self.parentViewController.navigationController ...]
来推送我的视图,但没有成功。
这是我的 popOver 代码(在 MainVC.h 中):
-(IBAction)showPopoverSearch:(id)sender
UIBarButtonItem *btn = (UIBarButtonItem *) sender;
NSInteger width = 600;
NSInteger height = 400;
SearchViewController *searchVC = [self.storyboard instantiateViewControllerWithIdentifier:@"searchView"];
searchVC.modalInPopover = NO;
UINavigationController* contentViewController = [[UINavigationController alloc] initWithRootViewController:searchVC];
popoverController = [[WYPopoverController alloc] initWithContentViewController:contentViewController];
popoverController.delegate = self;
//popoverController.passthroughViews = @[btn];
popoverController.popoverContentSize = CGSizeMake(width, height);
popoverController.popoverLayoutMargins = UIEdgeInsetsMake(10, 10, 10, 10);
popoverController.wantsDefaultContentAppearance = YES;
[popoverController presentPopoverFromBarButtonItem:btn permittedArrowDirections:WYPopoverArrowDirectionAny animated:YES];
这是didSelctRow
方法(SearchViewController.m):
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main"bundle:nil];
PostReaderViewController *postReaderView =
(PostReaderViewController *)
[storyboard instantiateViewControllerWithIdentifier:@"postReader"];
postReaderView.thePost = [_postsArray objectAtIndex:indexPath.row];
// if ([self.parentViewController.po .popoverController isPopoverVisible])
// [popoverController dismissPopoverAnimated:YES];
[self.navigationController pushViewController:postReaderView animated:YES];
【问题讨论】:
你必须调用dismissPopoverAnimated方法 @UttamSinha 你认真地领导我的职位了吗? 【参考方案1】:为了解决这个问题,我将导航控制器和 popoverController 从父视图 MainVC.h
传递给子控制器 SearchViewController.h
,然后使用这些变量关闭我的 PopOvercontroller 并推送新的 VC。代码 sn-p:SearchView
@interface SearchViewController : UIViewController
@property (strong, nonatomic) WYPopoverController *parentPopoverVC;
@property (strong, nonatomic) UINavigationController *parentNavigationController;
@end
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
...
[self.parentPopoverVC dismissPopoverAnimated:YES];
[self.parentNavigationController pushViewController:postReaderView animated:YES];
MainVC.h
-(IBAction)showPopoverSearch:(id)sender
SearchViewController *searchVC = [self.storyboard instantiateViewControllerWithIdentifier:@"searchView"];
[searchVC setParentPopoverVC:popoverController];
[searchVC setParentNavigationController:self.navigationController];
[popoverController presentPopoverFromBarButtonItem:btn permittedArrowDirections:WYPopoverArrowDirectionAny animated:YES];
【讨论】:
以上是关于从自定义 UIPopOver 问题推送新的 UIViewController的主要内容,如果未能解决你的问题,请参考以下文章
.Net Core:从自定义异常中间件返回 IActionResult