Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6143399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:31:12+00:00 2026-05-23T18:31:12+00:00

I have followed several tutorials/examples/answers, etc., to try and have a Cancel button within

  • 0

I have followed several tutorials/examples/answers, etc., to try and have a Cancel button within a popoverController use the delegate method to dismiss the popover (itself). I have had no luck and I’m stuck. Below are the pertinent code snippets.

I know the cancelButtonPushed method is being called successfully, but my golden method “didClickCancelButton” is never being called.

Any insight?

Here is what I have:

//
//  MIPracticeAreasFilterViewController.h
//

#import <UIKit/UIKit.h>

@protocol MyPopoverDelegate 
-(void)didClickCancelButton;
@end

@interface MIPracticeAreasFilterViewController : UITableViewController {
    //other vars
    id <MyPopoverDelegate> delegate;

}

//other properties
@property (nonatomic, assign) id <MyPopoverDelegate> delegate; 

//other methods    
-(IBAction)cancelButtonPush:(id)sender;

@end


//
//  MIPracticeAreasFilterViewController.m
//

#import "MIPracticeAreasFilterViewController.h"

@interface MIPracticeAreasFilterViewController()
    -(UITableViewCell *)buttonCellForTableView:(UITableView*)tableView;
    -(UITableViewCell *)submitOrCancelCellForTableView:(UITableView*)tableView;
@end

@implementation MIPracticeAreasFilterViewController
@synthesize practiceAreas=_practiceAreas;
@synthesize selectedPracticeAreas=_selectedPracticeAreas;
@synthesize delegate;

- (id)initWithStyle:(UITableViewStyle)style
{
    //init stuff
}

- (void)dealloc
{

}

- (void)didReceiveMemoryWarning
{

}

-(IBAction)cancelButtonPush:(id)sender
{
    if (self.delegate == nil)
    {
        NSLog(@"Delegate is nil. Cancel button pushed.");
    }
    //[[self delegate] didClickCancelButton];
    [self.delegate didClickCancelButton];

}

- (UITableViewCell *)submitOrCancelCellForTableView:(UITableView *)tableView
{
    static NSString *CellIdentifier = @"PracticeAreaSubmitOrCancelCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    NSUInteger buttonSpace = 10;
    NSUInteger buttonWidth = 120;
    NSUInteger buttonHeight = 34;
    NSUInteger buttonStartX = 80;
    NSUInteger buttonY = 4;

    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [cancelButton addTarget:self action:@selector(cancelButtonPush:) forControlEvents:UIControlEventTouchUpInside];
    cancelButton.frame = CGRectMake(buttonStartX + buttonWidth*1 + buttonSpace*1, buttonY, buttonWidth, buttonHeight);
    [cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
    [cell.contentView addSubview:cancelButton];

    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        //clicked the "select" cell, all the handlers are their responsibility.
        return;
    }

    if (indexPath.row == 1) {
        //clicked the "submit or cancel" cell, all the handlers are their responsibility.
        return;
    }

    NSString *practiceArea = [_practiceAreas objectAtIndex:indexPath.row-2];

    if ([_selectedPracticeAreas containsObject:practiceArea]) {
        //remove the object
        [_selectedPracticeAreas removeObject:practiceArea];
    } else {
        [_selectedPracticeAreas addObject:practiceArea];
    }
    [tableView reloadData];
}

@end

And here is the view controller that creates the popoverController:

//
//  MIRootViewController.h
//

#import <UIKit/UIKit.h>
#import "MILandingPageViewController.h"
#import "MIPracticeAreasFilterViewController.h"
#import "MILoginViewController.h"

@interface MIRootViewController : UIViewController <UIPopoverControllerDelegate, UITextFieldDelegate, MILoginCompleteDelegate, MIInterfaceOrientationDelegate, UINavigationControllerDelegate, MyPopoverDelegate>
{
    //other objects

    UIPopoverController *_practiceAreasPopoverController;
    MIPracticeAreasFilterViewController *_practiceAreasFilterViewController;

}

//other properties
@property (nonatomic, readwrite, retain) UIPopoverController *practiceAreasPopoverController;
@property (nonatomic, readwrite, retain) MIPracticeAreasFilterViewController *practiceAreasFilterViewController;

//other methods
- (void) didClickCancelButton;

@end

//
//  MIRootViewController.m
//

#import "MIRootViewController.h"
#import "HLReachability.h"
#import "MILoginStatusManager.h"
#import "MITextInsightDataUpdater.h"

@interface MIRootViewController ()

//other methods
- (void)didClickCancelButton;

@end

@implementation MIRootViewController

@synthesize practiceAreasPopoverController = _practiceAreasPopoverController;
@synthesize practiceAreasFilterViewController = _practiceAreasFilterViewController;

- (void)dealloc
{
    //stuff
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        [self initialize];
    }
    return self;
}

- (void)initialize
{

    [[MIAppModel sharedInstance] preloadImages];

    _practiceAreasFilterViewController = [[MIPracticeAreasFilterViewController alloc] initWithStyle:UITableViewStylePlain];
    _practiceAreasPopoverController = [[UIPopoverController alloc] initWithContentViewController:_practiceAreasFilterViewController];
    _practiceAreasPopoverController.popoverContentSize = CGSizeMake(400, 900);
    _practiceAreasPopoverController.delegate = self;

}

#pragma mark MyPopover delegate

-(void)didClickCancelButton
{
    NSLog(@"Success! Clicked Cancel from ROOT VIEW");

    if ([_practiceAreasPopoverController isPopoverVisible])
    {
        [_practiceAreasPopoverController dismissPopoverAnimated:YES];
        [_practiceAreasPopoverController release];
    }     
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    //bring back the popover if it was visible before the rotation
    if (_practiceAreasPopoverControllerWasVisible) 
    {
        CGRect popoverFrame = _practiceAreasButton.superview.frame;
        popoverFrame.origin.x += _practiceAreasButton.frame.origin.x;
        popoverFrame.origin.y += _practiceAreasButton.frame.origin.y;
        popoverFrame.size = _practiceAreasButton.frame.size;
        popoverFrame.size.height = _practiceAreasButton.frame.size.height;
        [_practiceAreasPopoverController presentPopoverFromRect:popoverFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:NO];
    }
    [_navController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    _practiceAreasPopoverControllerWasVisible = [_practiceAreasPopoverController isPopoverVisible];
    if (_practiceAreasPopoverControllerWasVisible) {
        //hide it before the rotation
        [_practiceAreasPopoverController dismissPopoverAnimated:NO];
    }
    [_navController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

#pragma mark - Actions

- (IBAction) practiceAreasTouch:(id)sender
{
    [_searchInput resignFirstResponder];
    [_practiceAreasPopoverController setDelegate:self];
    if (![_practiceAreasPopoverController isPopoverVisible]) {
        //show the popover
        CGRect popoverFrame = _practiceAreasButton.superview.frame;
        popoverFrame.origin.x += _practiceAreasButton.frame.origin.x;
        popoverFrame.origin.y += _practiceAreasButton.frame.origin.y;
        popoverFrame.size = _practiceAreasButton.frame.size;
        popoverFrame.size.height = _practiceAreasButton.frame.size.height;
        [_practiceAreasPopoverController presentPopoverFromRect:popoverFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
    }
    else
    {
        [_practiceAreasPopoverController dismissPopoverAnimated:NO];
    }
}

#pragma mark - Practice Areas Filter PopoverControllerDelegate
- (void) popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
    if ([_searchInput.text isEqualToString:@""]) {
        //just use the insights
        _landingPageController.textInsights = [[MIAppModel sharedInstance] textInsightsForTopics:_practiceAreasFilterViewController.selectedTopics ];
    }
    else 
    {
        //filter by search as well
        _landingPageController.textInsights = [[MIAppModel sharedInstance] textInsightsForTopics:_practiceAreasFilterViewController.selectedTopics matchingSearch:_searchInput.text ];
    }
    [self showBackButtonAnimated:YES];
    _filterOn = YES;
    [_landingPageController.layoutView reloadDataWithInterfaceOrientation:self.interfaceOrientation];
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:31:12+00:00Added an answer on May 23, 2026 at 6:31 pm

    I should have caught this. I needed to set the delegate on my viewController, not my popoverController.

    _practiceAreasFilterViewController.delegate = self;
    

    instead of

    _practiceAreasPopoverController.delegate = self;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an if statement followed by several else if statements. All of the
I am new to rails so could use some help here. I have followed
I have been reading several tutorials and watching some iTube videos to see how
I have a Binary file that has several names followed by some details (50
I have followed a few online tutorials and managed to install custom item templates
I have a function in which I pass a filename followed by several integer
I have several numbers in a string, such as: 8;# 10;# 34;# etc... I
I've been digging into EmberJS for one day :). I've followed several examples. Some
I have followed all the instructions here: http://www.tonyspencer.com/2003/10/22/curl-with-php-and-apache-on-windows/ to install & config apache get
I have followed the blog post written by Steve Sanderson at blog.codeville.net/2008/10/14/partial-requests-in-aspnet-mvc . It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.