Search code examples
iphoneiosuipopovercontroller

Using UIPopover for a comment button


I have to create a UITableView of a social site

Now I got stuck on uitableview cell, which contains a comment button.

On click on that comment button, I want to create a Popover (in which a user can type and post).

NB: this is an iPhone app not iPad

Is it possibe? If so, please help me. And also please tell me if there are any good tutorial/sample codes.


Solution

  • It is possible. Yet, since you're on the iPhone, you need a 3-party popover class (most probably WEPopover (https://github.com/werner77/WEPopover)

    Then, you can setup your popover and display it from your button.

    As a simple iPad example, here is a class I created to make it simple to create a UIPopover :

    +(UIPopoverController*)displayPopoverForRowIndex:(NSInteger)index inView:(UIView*)view fromRect:(CGRect)rect withTitle:(NSString*)title permittedArrowDirections:(UIPopoverArrowDirection)direction
    {
        UIViewController *contentVC = [[NDSearchDetailsController alloc] initWithIndex:index];
        UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:contentVC];
    
        tableVC.navigationController = navVC;
    
        UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navVC];
        tableVC.popoverController = popover;
    
        popover.delegate = tableVC;
    
        if (view) [popover presentPopoverFromRect:rect inView:view permittedArrowDirections:direction animated:YES];
    
        return popover;
    }