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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:58:12+00:00 2026-05-15T19:58:12+00:00

I’m new to this and in my application I use UISearchBar . When I

  • 0

I’m new to this and in my application I use UISearchBar. When I enter any word to search in it the application crashes.

In my project I am using sqlite and values are fetched from the db in AppDelegate and saved in an NSMutableArray named docArray.

RootViewController.m

    - (void)viewDidLoad{
        listOfItems = [[NSMutableArray alloc] init];
        NSDictionary *value = [NSDictionary dictionaryWithObject:appDelegate.docArray forKey:@"doctors"];
        [listOfItems addObject:value];
        //  Intialize copy array that will store the result of search result
        copyListOfItems = [[NSMutableArray alloc] init];
            //  Add Search bar to main view .....
        self.tableView.tableHeaderView = searchBar;
        searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
        searching = NO;
        letUserSelectRow = YES;
    }

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
         if (searching)
        return 1;
     else
        return 1;
    }


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

    {
         if (searching)
        return [copyListOfItems count];
     else
        return [appDelegate.arryData count];
    }


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
         static NSString *CellIdentifier = @"Cell";

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

     if (searching)
     {
        waitsup *wu = [copyListOfItems objectAtIndex:indexPath.row];

        [cell.textLabel setText:[NSString stringWithFormat:@"%@ %@ %@", wu.first_name, wu.last_name, wu.title]];
        cell.imageView.image = [UIImage imageNamed:@"wudoc.jpg"];
        [cell.detailTextLabel setText:[NSString stringWithFormat:@"%@ %@ %@", wu.city, wu.state, wu.zipcode]];

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
     }
         else
     {
        waitsup *wu = [appDelegate.arryData objectAtIndex:indexPath.row];

        [cell.textLabel setText:[NSString stringWithFormat:@"%@ %@ %@", wu.first_name, wu.last_name, wu.title]];
        cell.imageView.image = [UIImage imageNamed:@"wudoc.jpg"];
        [cell.detailTextLabel setText:[NSString stringWithFormat:@"%@ %@ %@", wu.city, wu.state, wu.zipcode]];

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
         }

         return cell;
     }

    -(void)searchBarTextDidBeginEditing :(UISearchBar *)theSearchBar {
    NSLog(@"Now in searchBarTextDidBeginEditing");

    searching = YES;
    letUserSelectRow = NO;

    self.tableView.scrollEnabled = NO;

    //  Add Done button ........
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
                                               initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                               target:self action:@selector(doneSearching_clicked:)]
                                              autorelease];

}


-(NSIndexPath *)tableView :(UITableView *)theTableView willSelectRowAtIndexPath :(NSIndexPath*)indexPath {
    NSLog(@"will select Row At Index Path");

    if (letUserSelectRow)
    {
        return indexPath;
    }
    else
    {
        return nil;
    }

}


-(void)searchBar :(UISearchBar*)theSearchBar textDidChange :(NSString*)searchText {
    NSLog(@"textDidChange");

    //  it is done so that data can be selected as new search
    [copyListOfItems removeAllObjects];

    if ([searchText length] > 0)
    {
        searching = YES;
        letUserSelectRow = YES;
        self.tableView.scrollEnabled = YES;

        [self searchTableView];
    }
    else
    {
        searching = NO;
        letUserSelectRow = NO;
        self.tableView.scrollEnabled = NO;
    }

    [self.tableView reloadData];

}


-(void)searchBarSearchButtonClicked :(UISearchBar*)theSearchBar {
    NSLog(@"searchBarSearchButtonClicked");
    [self searchTableView];
}


-(void)searchTableView {
    NSLog(@"searchTableView");

    NSString *searchText = searchBar.text;
    NSMutableArray *searchArray = [[NSMutableArray alloc] init];

    for (NSDictionary *dictionary in listOfItems)
    {
        NSArray *array = [dictionary objectForKey:@"first_name"];
        [searchArray addObjectsFromArray:array];
    }


    for (waitsup *sTemp in searchArray)
    {
        NSRange titleResultsRange = [[NSString stringWithFormat:@"%@ %@",sTemp.first_name, sTemp.last_name] rangeOfString:searchText options:NSCaseInsensitiveSearch];

        if (titleResultsRange.length > 0)
        {
            NSLog(@"%@", sTemp);
            [copyListOfItems addObject:sTemp];
        }

    }


    [searchArray release];
    searchArray = nil;
}


-(void)doneSearching_clicked:(id)sender {
    NSLog(@"doneSearching_clicked");

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

    letUserSelectRow = YES;
    searching = NO;

    self.navigationItem.rightBarButtonItem = nil;
    self.tableView.scrollEnabled = YES;

    [self.tableView reloadData];    
}

console show following error :

2010-07-22 13:36:16.002 wu2[1077:207] Processing Element: array

2010-07-22 13:36:16.004 wu2[1077:207] Processing Element: XML_Serializer_Tag

2010-07-22 13:36:16.005 wu2[1077:207] Processing Element: id

2010-07-22 13:36:16.005 wu2[1077:207] Processing Value: 1

2010-07-22 13:36:16.006 wu2[1077:207] Processing Element: first_name

2010-07-22 13:36:16.007 wu2[1077:207] Processing Value: Prateek

2010-07-22 13:36:16.007 wu2[1077:207] Processing Element: middle_name

2010-07-22 13:36:16.008 wu2[1077:207] Processing Value: K

2010-07-22 13:36:16.008 wu2[1077:207] Processing Element: last_name

2010-07-22 13:36:16.009 wu2[1077:207] Processing Value: Bhanot

2010-07-22 13:36:16.009 wu2[1077:207] Processing Element: title

2010-07-22 13:36:16.010 wu2[1077:207] Processing Value: Er.

2010-07-22 13:36:16.011 wu2[1077:207] Processing Element: org_name

2010-07-22 13:36:16.011 wu2[1077:207] Processing Value: Cyber

2010-07-22 13:36:16.012 wu2[1077:207] Processing Element: upin

2010-07-22 13:36:16.014 wu2[1077:207] Processing Value: 34242

2010-07-22 13:36:16.014 wu2[1077:207] Processing Element: npi

2010-07-22 13:36:16.015 wu2[1077:207] Processing Value: 2343242

2010-07-22 13:36:16.015 wu2[1077:207] Processing Element: address1

2010-07-22 13:36:16.015 wu2[1077:207] Processing Value: Maler Kotla

2010-07-22 13:36:16.016 wu2[1077:207] Processing Element: address2

2010-07-22 13:36:16.016 wu2[1077:207] Processing Value: Mohali

2010-07-22 13:36:16.018 wu2[1077:207] Processing Element: city

2010-07-22 13:36:16.018 wu2[1077:207] Processing Value: Chandigarh

2010-07-22 13:36:16.018 wu2[1077:207] Processing Element: state

2010-07-22 13:36:16.019 wu2[1077:207] Processing Value: Punja

2010-07-22 13:36:16.020 wu2[1077:207] Processing Element: zipcode

2010-07-22 13:36:16.020 wu2[1077:207] Processing Value: 12345

2010-07-22 13:36:16.021 wu2[1077:207] Processing Element: country

2010-07-22 13:36:16.022 wu2[1077:207] Processing Value: India

2010-07-22 13:36:16.022 wu2[1077:207] Processing Element: county

2010-07-22 13:36:16.023 wu2[1077:207] Processing Element: office_phone1

2010-07-22 13:36:16.025 wu2[1077:207] Processing Value: 13123131

2010-07-22 13:36:16.027 wu2[1077:207] Processing Element: fax1

2010-07-22 13:36:16.028 wu2[1077:207] Processing Value: 2131231

2010-07-22 13:36:16.028 wu2[1077:207] Processing Element: gender

2010-07-22 13:36:16.029 wu2[1077:207] Processing Value: male

2010-07-22 13:36:16.030 wu2[1077:207] Processing Element: status

2010-07-22 13:36:16.030 wu2[1077:207] Processing Value: active

2010-07-22 13:36:16.031 wu2[1077:207] Processing Element: profiletype

2010-07-22 13:36:16.031 wu2[1077:207] Processing Value: user

2010-07-22 13:36:16.032 wu2[1077:207] Processing Element: entity

2010-07-22 13:36:16.033 wu2[1077:207] Processing Value: practice

2010-07-22 13:36:16.034 wu2[1077:207] Processing Element: XML_Serializer_Tag

2010-07-22 13:36:16.035 wu2[1077:207] Processing Element: id

2010-07-22 13:36:16.035 wu2[1077:207] Processing Value: 2

2010-07-22 13:36:16.036 wu2[1077:207] Processing Element: first_name

2010-07-22 13:36:16.036 wu2[1077:207] Processing Value: Hitu

2010-07-22 13:36:16.037 wu2[1077:207] Processing Element: middle_name

2010-07-22 13:36:16.038 wu2[1077:207] Processing Value: k

2010-07-22 13:36:16.038 wu2[1077:207] Processing Element: last_name

2010-07-22 13:36:16.039 wu2[1077:207] Processing Value: bansal

2010-07-22 13:36:16.040 wu2[1077:207] Processing Element: title

2010-07-22 13:36:16.040 wu2[1077:207] Processing Value: Doctor

2010-07-22 13:36:16.041 wu2[1077:207] Processing Element: org_name

2010-07-22 13:36:16.041 wu2[1077:207] Processing Value: Cyebertron

2010-07-22 13:36:16.042 wu2[1077:207] Processing Element: upin

2010-07-22 13:36:16.042 wu2[1077:207] Processing Value: 34242

2010-07-22 13:36:16.043 wu2[1077:207] Processing Element: npi

2010-07-22 13:36:16.043 wu2[1077:207] Processing Value: 2343242

2010-07-22 13:36:16.044 wu2[1077:207] Processing Element: address1

2010-07-22 13:36:16.045 wu2[1077:207] Processing Value: Mohali

2010-07-22 13:36:16.045 wu2[1077:207] Processing Element: address2

2010-07-22 13:36:16.046 wu2[1077:207] Processing Value: chd

2010-07-22 13:36:16.046 wu2[1077:207] Processing Element: city

2010-07-22 13:36:16.047 wu2[1077:207] Processing Value: Chandigarh

2010-07-22 13:36:16.048 wu2[1077:207] Processing Element: state

2010-07-22 13:36:16.048 wu2[1077:207] Processing Value: Punja

2010-07-22 13:36:16.049 wu2[1077:207] Processing Element: zipcode

2010-07-22 13:36:16.049 wu2[1077:207] Processing Value: 12345

2010-07-22 13:36:16.050 wu2[1077:207] Processing Element: country

2010-07-22 13:36:16.050 wu2[1077:207] Processing Value: India

2010-07-22 13:36:16.051 wu2[1077:207] Processing Element: county

2010-07-22 13:36:16.051 wu2[1077:207] Processing Value: jljljlkj

2010-07-22 13:36:16.052 wu2[1077:207] Processing Element: office_phone1

2010-07-22 13:36:16.053 wu2[1077:207] Processing Value: 12-32-3-3

2010-07-22 13:36:16.053 wu2[1077:207] Processing Element: fax1

2010-07-22 13:36:16.054 wu2[1077:207] Processing Value: 12331331

2010-07-22 13:36:16.054 wu2[1077:207] Processing Element: gender

2010-07-22 13:36:16.055 wu2[1077:207] Processing Value: male

2010-07-22 13:36:16.056 wu2[1077:207] Processing Element: status

2010-07-22 13:36:16.056 wu2[1077:207] Processing Value: active

2010-07-22 13:36:16.057 wu2[1077:207] Processing Element: profiletype

2010-07-22 13:36:16.057 wu2[1077:207] Processing Value: dr411

2010-07-22 13:36:16.058 wu2[1077:207] Processing Element: entity

2010-07-22 13:36:16.058 wu2[1077:207] Processing Value: provider

2010-07-22 13:36:16.059 wu2[1077:207] No Errors

2010-07-22 13:36:20.923 wu2[1077:207] Now in searchBarTextDidBeginEditing

2010-07-22 13:36:22.899 wu2[1077:207] textDidChange

2010-07-22 13:36:22.900 wu2[1077:207] searchTableView

2010-07-22 13:36:22.901 wu2[1077:207] <waitsup: 0x6e14fc0>

2010-07-22 13:36:22.985 wu2[1077:207] textDidChange

2010-07-22 13:36:22.986 wu2[1077:207] searchTableView

2010-07-22 13:36:22.987 wu2[1077:207] <waitsup: 0x6e14fc0>

2010-07-22 13:36:23.073 wu2[1077:207] textDidChange

2010-07-22 13:36:23.074 wu2[1077:207] searchTableView

2010-07-22 13:36:23.075 wu2[1077:207] <waitsup: 0x6e14fc0>

2010-07-22 13:36:23.249 wu2[1077:207] textDidChange

2010-07-22 13:36:23.250 wu2[1077:207] searchTableView

2010-07-22 13:36:23.250 wu2[1077:207] <waitsup: 0x6e14fc0>

2010-07-22 13:36:23.449 wu2[1077:207] textDidChange

2010-07-22 13:36:23.450 wu2[1077:207] searchTableView

2010-07-22 13:36:23.450 wu2[1077:207] <waitsup: 0x6e14fc0>

2010-07-22 13:36:23.625 wu2[1077:207] textDidChange

2010-07-22 13:36:23.626 wu2[1077:207] searchTableView

2010-07-22 13:36:23.626 wu2[1077:207] <waitsup: 0x6e14fc0>

2010-07-22 13:36:23.777 wu2[1077:207] textDidChange

2010-07-22 13:36:23.778 wu2[1077:207] searchTableView

2010-07-22 13:36:23.778 wu2[1077:207] <waitsup: 0x6e14fc0>

2010-07-22 13:36:24.377 wu2[1077:207] searchBarSearchButtonClicked

2010-07-22 13:36:24.377 wu2[1077:207] searchTableView

2010-07-22 13:36:24.378 wu2[1077:207] <waitsup: 0x6e14fc0>

2010-07-22 13:36:26.157 wu2[1077:207] doneSearching_clicked

2010-07-22 13:36:26.161 wu2[1077:207] textDidChange

2010-07-22 13:36:26.161 wu2[1077:207] searchTableView

2010-07-22 13:36:26.162 wu2[1077:207] <waitsup: 0x6e14fc0>

2010-07-22 13:36:26.162 wu2[1077:207] <waitsup: 0x6e16100>

2010-07-22 13:36:27.071 wu2[1077:207] Now in searchBarTextDidBeginEditing

2010-07-22 13:36:28.329 wu2[1077:207] textDidChange

2010-07-22 13:36:28.330 wu2[1077:207] searchTableView

2010-07-22 13:36:30.221 wu2[1077:207] doneSearching_clicked

2010-07-22 13:36:30.224 wu2[1077:207] textDidChange

2010-07-22 13:36:30.224 wu2[1077:207] searchTableView

2010-07-22 13:36:30.225 wu2[1077:207] <waitsup: 0x6e14fc0>

2010-07-22 13:36:30.226 wu2[1077:207] <waitsup: 0x6e16100>
  • 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-15T19:58:12+00:00Added an answer on May 15, 2026 at 7:58 pm

    for one thing, please condense your code so we don’t have to scroll through all the newlines. Furthermore, is this the dataSource of your table view, and if so, where are:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    

    they have to access copyListOfItems, which may fail and be the source of your crash.

    What does the console show when it crashes?

    edit: thanks for providing the extra info. Your problem lies here:

    for (NSString *sTemp in searchArray)
    

    searchArray contains “waitsup” objects, I think, not NSString. You cast it to an NSString pointer, but it’s your responsibility that it actually points to an NSString object. Therefore you get the error that rangeOfString is called on a waitsup, which is “unrecognized”. You cannot then call rangeOfString on the waitsup object, if you didn’t provide the rangeOfString method in it yourself.

    Looking at the rest of your code, I think you could fix it like this:

    for (waitsup *sTemp in searchArray) {
        NSRange titleResultsRange = [sTemp.name_last rangeOfString:searchText options:NSCaseInsensitiveSearch];
        if (titleResultsRange.length > 0)
            [copyListOfItems addObject:sTemp];
    }
    

    but then only name_last is searched. Expanding this to include more fields is trivial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want use html5's new tag to play a wav file (currently only supported
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.