从自定义UIPopOver问题推出新的UIViewController

时间:2015-04-03 10:57:38

标签: ios objective-c uitableview uiviewcontroller uinavigationcontroller

您好我使用此library来显示包含带有searchBar的tableView的PopOver。 问题是一个用户尝试从tableView中选择行而不是关闭popOver并在空洞屏幕中显示选中的行我得到了这个: enter image description here。 我尝试使用[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];

}

1 个答案:

答案 0 :(得分:0)

要解决此问题,我已将导航控制器和popoverController从父视图MainVC.h传递到子控制器SearchViewController.h,然后使用这些变量来关闭我的PopOvercontroller并推送新的VC。代码段:
搜索查看

@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];

}