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 6249199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:11:35+00:00 2026-05-24T13:11:35+00:00

I created a UISearchBar. It is working but not the way I want. If

  • 0

I created a UISearchBar. It is working but not the way I want. If I enter any first letter on the UISearchbar and then I click on the SearchButton, it doesn’t work but when I push the next controller and I come back, then I see my search result in TableView. The first time my TableView does not refresh.

Here is my custom cell class and my controller class

@synthesize myTableView;
@synthesize tabledata;

#pragma mark -
#pragma mark Initialization
#pragma mark -
#pragma mark View lifecycle

-(void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = self.editButtonItem;
    app = (JourneyAppDelegate *)[[UIApplication sharedApplication]delegate];
    sBar =[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 30)]; 
    sBar.delegate=self;   
    [self.view addSubview:sBar];
    searcheddata =[[NSMutableArray alloc]init];
    NSLog(@"*************:%&",list);
    list=[[NSMutableArray alloc]init]; 
    tabledata =[[NSMutableArray alloc]init]; 
    list = [app.journeyList retain];
    [tabledata addObjectsFromArray:list];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100.0;
}

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [tabledata count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{ 
    NSLog(@"*************:%&",list);
    static NSString *CellIdentifier = @"Cell";
    TJourneyListCell *cell =(TJourneyListCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    { 
        cell = [[[TJourneyListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];    
        NSLog(@"%@",cell); 
    }          
    NewJourney *newjoruneobject = [tabledata objectAtIndex:indexPath.row]; 
    cell.namelbl.text = newjoruneobject.journeyname;  
    cell.distancelbl.text = newjoruneobject.journeylocation;  
    cell.infolbl.text = newjoruneobject.journeydescription;   
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
    return cell; 
}

#pragma mark UISearchBarDelegate 
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar 
{ 
    // only show the status bar’s cancel button while in edit mode 
    [tabledata removeAllObjects];
    sBar.showsCancelButton = YES; 
    [searchBar setShowsCancelButton:YES animated:YES];
    sBar.autocorrectionType = UITextAutocorrectionTypeNo; 
} 

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

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
{
    [tabledata removeAllObjects];// remove all data that belongs to previous search

    if([sBar.text length] != 0)//|| searchText==nil) 
    { 
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"journeyname contains[cd] %@", searchBar.text];
        [tabledata addObjectsFromArray:[list filteredArrayUsingPredicate: predicate]];
        [myTableView reloadData];
        return;
         }
    NSLog(@"Counter:-'%d'",[tabledata count]);
    [myTableView reloadData];
}


- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar 
{ // if a valid search was entered but the user wanted to cancel, bring back the main list content 
    [tabledata removeAllObjects]; 
    [tabledata addObjectsFromArray:list];
    @try
    { 
        [myTableView reloadData];
    }
    @catch(NSException *e)
    { 
    } 
    [sBar resignFirstResponder];
    sBar.text = @" "; 
} 

// called when Search (in our case “Done”) button pressed 
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 
{ 

    [searchBar resignFirstResponder]; 
    myTableView.allowsSelection = YES;
    myTableView.scrollEnabled = YES;
    [myTableView reloadData];
}

- (void)dealloc {
    [super dealloc];
    [mLable1 release];
    [myTableView release], myTableView = nil;
    [tabledata dealloc];
}

@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-24T13:11:35+00:00Added an answer on May 24, 2026 at 1:11 pm
    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        [tableView reloadData];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on UISearchBar which I have created programmatically. Below is what I
Created a Location alarm based app. Everything is working fine on emulator. But the
I am trying to create a customized UISearchBar. I am not able to find
Created an OpenGraph action and object. Trying to submit my action. When I click
Created new scaffold Users that has fields name & description All working as suppose
Created a AlertDialog that is used to prompting the user to enter a keyword.
I saw this post on SO: UISearchBar solid color But no answer was provided.
I'm using a UISearchViewController in a slightly non-conventional way. My UISearchBar is initially hidden.
I want to save the switch state. I created custom cell class witch print
I have created an UISearchBar and I have to insert a view in inputAccessoryView

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.