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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:53:48+00:00 2026-05-24T20:53:48+00:00

Here is my code below: – (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger row

  • 0

Here is my code below:

- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        
    NSInteger row = [indexPath row];
    NSString *contentForThisRow = nil;
    NSString *contentForThisRow2 = nil;
    
    if (mySearchBar.text > 0)
    {
        contentForThisRow = [self.filteredListContent objectAtIndex:row];
        NSInteger noWordIndex = [self.noWords indexOfObject:contentForThisRow];
        contentForThisRow2 = [self.enWords objectAtIndex:noWordIndex];
            NSLog (@"if success?");     
    }
        else 
    {
        contentForThisRow = [self.noWords objectAtIndex:row] ;
        contentForThisRow2 = [self.enWords objectAtIndex:row];
        NSLog (@"else success?");
    }
    
    static NSString *kCellID = @"cellID";

//standard code here etc for this method..

}

The codes above work perfectly except whenever I have used searchBar to filter and then click on Cancel button in the searchBar or Search button in the keyboard and then when I click on my custom "change" button in the navigationbar, the app crashes.

Before I use searchBar, there show up 4 NSLog after each change like:

  • 2011-08-15 17:21:24.481 Enne1[4750:207] else success?
  • 2011-08-15 17:21:24.483 Enne1[4750:207] else success?
  • 2011-08-15 17:21:24.484 Enne1[4750:207] else success?
  • 2011-08-15 17:21:24.485 Enne1[4750:207] else success?

And when I use searchBar to filter words, there show up also 4 NSLog like this:

  • 2011-08-15 17:19:33.713 E1[4744:207] if success?
  • 2011-08-15 17:19:33.714 E1[4744:207] if success?
  • 2011-08-15 17:19:33.714 E1[4744:207] if success?
  • 2011-08-15 17:19:33.715 E1[4744:207] if success?

But when after I have used searchBar and then cleared the searchText either with Cancel or Search and then click on "change button", there show up only 1 NSLog like this:
2

  • 011-08-15 17:21:49.806 E1[4750:207] if success?

It should be

  • else success

    in order to show the full lists, not

  • if success

.

Am I missing something?

EDIT 15 august:
I have tried

if(mySearchBar.text.length > 0)

as well, but the tableview shows nothing when I clear my search string and there came up only 2 nslogs, that is:

  • 2011-08-15 23:49:06.624 E1[5064:207] if success?
  • 2011-08-15 23:49:06.626 E1[5064:207] if success?

By the way, why does it show up 4 nslogs each time I enter one alphabet in the search bar? Shouldnt it show only one nslog each time?

And my codes for textDidChange is:

 - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchString
    
    {
NSLog (@" ss: %@", searchString);
        if ([searchString length] == 0) {
            [self performSelector:@selector(hideKeyboardWithSearchBar:) withObject:searchBar afterDelay:0];
            NSLog (@" searchstring: %@", searchString);
        }   
         [self filterContentForSearchText:searchString]; 
        [tableView reloadData];
        NSLog (@"has reloaded!");
        
        return;
    }

Edit 15 august; This is wrong: I suspect the code above is causing the app crashing? not reloading tableview properly?
Am I right? NSLog for searchString showed nothing…

2nd edit 15 august: I added NSLog (@" ss: %@", searchString); and of course it shows alphabet(s) each time I enter one alphabet. So it must be something wrong with mySearchBar.text > 0, how should I write this properly?

By the way, I added tableview and searchbar programmatically, tableviews delegate and datasource is linked to self and searchbars delegate is linked to self as well. There is nothing in InterfaceBuilder, only UIView.

  • 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-24T20:53:48+00:00Added an answer on May 24, 2026 at 8:53 pm

    Ah, I solved it by adding length to mySearchBar.text; mySearchBar.text.length > 0 works. I forgot to rewrite in another method, I changed mySearchBar.text to mySearchBar.text.length, that is:

    - (NSInteger)tableView:(UITableView *)tableView1 numberOfRowsInSection:(NSInteger)section
    {
    
        tableView1.rowHeight = 100 ;
        tableView1.separatorColor = [UIColor colorWithRed:0.40 green:0.70 blue:0.45 alpha:1.0];
        tableView1.opaque = NO;
    
        if (mySearchBar.text.length > 0)
        {
            return [self.filteredListContent count];
            NSLog (@"if return");
        }
        else
        {
            return [self.noWords count];
            NSLog (@"else return");
        }
    
    }
    

    @Daniel R Hicks
    and
    @ColdLogic: So both you are right that it is wrong to use only mySearchBar.text. Thank you very much for pointing me in the right direction.

    But I still wonder why there come up 4 nslogs each time…


    EDIT 16 august:

    4 nslogs show up every time I launch the app, because there are 4 visible cells. My tableview.height is 100, so when I changed it to 50, 8 nslogs show up and as well as 8 visible cells.

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

Sidebar

Related Questions

I commented my code below to reflect what I am attempting to do here.
Hey all. Here is the scenario. I have the below code, and I'm needing
I'm trying to update an element in the XML document below: Here's the code:
Here is the code below I tried this call but it didnt work... even
I'm trying to make sense of the example code here (below Examples). I don't
UPDATE: I've posted the Renderer code below, since this code here doesn't seem to
The problem is described in the subj.; Here's my code below: CGColorSpaceRef colorSpace =
If you have a look here is the code below for future references. <h1>Accreditations</h1>
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code from MSDN . I don't understand why the work isn't just

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.