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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:56:59+00:00 2026-06-14T06:56:59+00:00

I created a subClass of UITextView with a searchBar, here is the code: #import

  • 0

I created a subClass of UITextView with a searchBar, here is the code:

#import "SezioniTableController.h"

@interface SezioniTableController ()

@end

@implementation SezioniTableController

@synthesize searchBar,searchDisplayController;
@synthesize arraySezioni,arrayFiltrato;
@synthesize objTesto;

- (id)initWithStyle:(UITableViewStyle)style andArray:(NSMutableArray *)array{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization

        self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
        self.searchBar.delegate = self;

        self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
        self.searchDisplayController.delegate = self;
        self.searchDisplayController.searchResultsDataSource = self;

        self.arraySezioni = array;
        self.arrayFiltrato = array;

    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void) loadView {}

#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 the number of rows in the section.

    return self.arrayFiltrato.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewStylePlain reuseIdentifier:@"MyIdentifier"];
    }

    self.objTesto = [arrayFiltrato objectAtIndex:indexPath.row];

    cell.textLabel.text = self.objTesto.titoloTesto;

    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */

    NSDictionary *dict = [NSDictionary dictionaryWithObject:[self.arrayFiltrato objectAtIndex:indexPath.row] forKey:@"Testo"];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"PassaggioTesto" object:self userInfo:dict];
        NSLog(@"Click");
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    return self.searchBar; //in .h, IBOutlet UISearchBar* search;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

    return 44;
}

- (BOOL) searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{

    [self filterContentForSearchText:searchString scope: [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

    NSLog(@"aa");

    //[[NSNotificationCenter defaultCenter] postNotificationName:@"ReloadTable" object:self];
    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

- (BOOL) searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption{

    [self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];

    NSLog(@"ab");

    //[[NSNotificationCenter defaultCenter] postNotificationName:@"ReloadTable" object:self];
    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

- (void) filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope{

    NSLog(@"a count:%d",self.arraySezioni.count);

    [self.arrayFiltrato removeAllObjects]; // First clear the filtered array.

    for (objTesto in self.arraySezioni){
        NSComparisonResult result = [objTesto.titoloTesto compare:searchText options:NSCaseInsensitiveSearch range:NSMakeRange(0, [searchText length])];
        if (result == NSOrderedSame){
            NSLog(@"Titolo: %@",objTesto.titoloTesto);
            [self.arrayFiltrato addObject:self.objTesto];
        }else{
            NSLog(@"Non trovato");
        }
    }
}

- (void)searchBarCancelButtonClicked:(UISearchBar *)saearchBar {
    [self.arrayFiltrato removeAllObjects];
    [self.arrayFiltrato addObjectsFromArray: self.arraySezioni];
}

@end

On my uiviewcontroller I create a table using the uitableview created with this code:

self.arrayTesti = [self.dataLoad leggiArgomentiDellaSezione:tag];

self.table = [[SezioniTableController alloc] initWithStyle:UITableViewStylePlain andArray:self.arrayTesti];

self.tableArgumentView.delegate = self.table;
self.tableArgumentView.dataSource = self.table;

[self.tableArgumentView reloadData];

The viewcontroller is for an iPad application, the table works perfectly but if I try to search something it doesn’t work!
Can you help me?

  • 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-06-14T06:57:00+00:00Added an answer on June 14, 2026 at 6:57 am

    If you assign

    self.arraySezioni = array;
    self.arrayFiltrato = array;
    

    then both self.arraySezioni and self.arrayFiltrato are pointers to the same array. Which means that if you empty one array with

    [self.arrayFiltrato removeAllObjects];
    

    then the other array self.arraySezioni (and the original array) are also empty.

    So at least self.arrayFiltrato should be a copy of the original array:

     self.arrayFiltrato = [array copy];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a subclass from UIView #import <UIKit/UIKit.h> @interface MeeSelectDropDownView : UIView { UILabel
I created an UIViewController subclass, and figured out that the default implementation of -loadView
I have created a subclass of UIControl called ToggleImageControl via the following code (with
I created a subclass AOBject from NSObject @interface AObject : NSObject { NSinteger m;
I've got a universal project here with storyboard. I've created a subclass of UIWindow
I created a subclass of UITextView and now I want to extend the default
I created a Subclass of UIViewController in my Project and linked it to a
I have created a subclass of UIImageView and I am handling the touches for
I have created a subclass of UITableViewController that is used as the custom class
I created a simple speech recognition service: for this purpose I created a subclass

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.