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

  • Home
  • SEARCH
  • 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 6532371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:59:37+00:00 2026-05-25T09:59:37+00:00

I have a UISearchBar setup and when its being used, it has an overlay

  • 0

I have a UISearchBar setup and when its being used, it has an overlay grey view that covers the rest of the table similar to how apple does it.

When I click this darkened view, it exits search mode, which is good, but when I search again, then again click the grey to exit, it crashes with EXC BAD ACCESS error.

Here is some related code:

enter image description here

The crash is always at [rvController doneSearching_Clicked:nil];

OverlayViewController.h

@interface OverlayViewController : UIViewController

@property (nonatomic, retain) ChooserViewController *rvController;
@property (nonatomic, retain) CPTViewController *cptViewController;


@implementation OverlayViewController

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [rvController doneSearching_Clicked:nil];
    [cptViewController doneSearching_Clicked:nil];
}

- (void) dealloc {
    [rvController release];
    [cptListViewController release];
    [super dealloc];
}

@end

Code for the actual VC with the search bar

- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar
{
    searching = YES;
    [ovController.view removeFromSuperview];
    letUserSelectRow = YES;
    self.tableView.scrollEnabled = YES;
    if (self.mySearchBar.text !=nil)
    {
        NSPredicate *predicate =[NSPredicate predicateWithFormat:@"(name contains[cd] %@) OR (code contains[cd] %@)", self.mySearchBar.text, self.mySearchBar.text];
        [fetchedResultsController.fetchRequest setPredicate:predicate];
    }
    else
    {
        NSPredicate *predicate =[NSPredicate predicateWithFormat:@"All"];
        [fetchedResultsController.fetchRequest setPredicate:predicate];
    }

    NSError *error = nil;
    if (![[self fetchedResultsController] performFetch:&error]) 
    {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        exit(-1);  // Fail
    } 

    self.searchArray = fetchedResultsController.fetchedObjects;

    [mySearchBar resignFirstResponder];

    [self.tableView reloadData];
}

- (void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    self.navigationItem.leftBarButtonItem = nil;

    if(searching)
        return;

    if(ovController == nil)
        ovController = [[OverlayViewController alloc] initWithNibName:@"OverlayView" bundle:[NSBundle mainBundle]];

    CGFloat yaxis = self.navigationController.navigationBar.frame.size.height;
    CGFloat width = self.view.frame.size.width;
    CGFloat height = self.view.frame.size.height;

    CGRect frame = CGRectMake(0, yaxis, width, height);
    ovController.view.frame = frame;    
    ovController.view.backgroundColor = [UIColor grayColor];
    ovController.view.alpha = 0.5;

    ovController.rvContrller = self;

    [self.tableView insertSubview:ovController.view aboveSubview:self.parentViewController.view];

    searching = YES;
    letUserSelectRow = NO;
    self.tableView.scrollEnabled = NO;

    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] 
                                               initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
                                               target:self action:@selector(doneSearching_Clicked:)] autorelease];
}

- (void) searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
    searchBar.showsCancelButton = NO;
}

- (void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText 
{
    [self.tableView insertSubview:ovController.view aboveSubview:self.parentViewController.view];

    searching = NO;
    letUserSelectRow = NO;
    self.tableView.scrollEnabled = NO;

    [self.tableView reloadData];
}
- (void) doneSearching_Clicked:(id)sender {

    mySearchBar.text = @"";
    [mySearchBar resignFirstResponder];

    letUserSelectRow = YES;
    searching = NO;
    self.navigationItem.rightBarButtonItem = nil;
    self.tableView.scrollEnabled = YES;

    [ovController.view removeFromSuperview];
    [ovController release];
    ovController = nil;

    [self.tableView reloadData];
    [self.tableView scrollToRowAtIndexPath:0 atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
  • 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-25T09:59:38+00:00Added an answer on May 25, 2026 at 9:59 am
    /// @OverlayView
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
        [rvController doneSearching_Clicked:nil]; ///< Point 1
        [cptViewController doneSearching_Clicked:nil];
    }
    
    /// @VC Search bar
    - (void) doneSearching_Clicked:(id)sender {
    
        mySearchBar.text = @"";
        [mySearchBar resignFirstResponder];
    
        letUserSelectRow = YES;
        searching = NO;
        self.navigationItem.rightBarButtonItem = nil;
        self.tableView.scrollEnabled = YES;
    
        /// Point 2 
        [ovController.view removeFromSuperview];
        [ovController release];
        ovController = nil;
    
        [self.tableView reloadData];
        [self.tableView scrollToRowAtIndexPath:0 atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }
    

    At the Point 1, it will call -(void)doneSearching_Clicked, then it will execute Point 2. At Point 2, I think the OverlayView object’s retainCount will be 0, that means it will deallocated. So, all pointers the OverlayView has may be invalid, because it releases those objects in -(void)dealloc. According to your codes, that is all I can know.

    Edit:
    The above procedures may be translated as following format. The -doneSearching_Click will result in [self release] behavior.

    /// @OverlayView
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
        [rvController doneSearching_Clicked:nil]; ///< Point 1
        /// [self release];  /// the above method will do such thing.
        [cptViewController doneSearching_Clicked:nil];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view controller with a table view and a UISearchBar. When the
I have a class that conforms to UISearchDisplayDelegate and contains a UISearchBar. This view
I have a UISearchBar which acts as a live filter for a table view.
I have implemented a UISearchBar into a table view and almost everything is working
I'm working on an application that has a view hierarchy that is very similar
I am trying to add a UISearchbar to table header view. I have the
I have a UISearchBar as a subview of a UIViewController's view. The UIViewController has
I have a UISearchBar that has a cancel button (it's displayed using -(void)setShowsCancelButton:animated ).
I have an UIViewController with several subviews in its view property ( UISearchbar and
I have a UITableView that has a subview UISearchBar attached via the Interface Builder.

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.