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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:48:15+00:00 2026-05-16T11:48:15+00:00

I have a UITableView, where I extend/shrink the cells with the following code. I

  • 0

I have a UITableView, where I extend/shrink the cells with the following code.
I save the last 2 indexPaths to perform a reloadRowsAtIndexPaths: on it.

Now I added a UISearchBar to the header for section 0. If I tab the searchBar, a KeyBoard is displayed on top of the UITableView — so far so good.

But I want the user to be able to touch the Cells and disable the KeyBoard. To do so, I test if the searchbox is the first responder inside the -tableView:didSelectRowAtIndexPath:

But doing so will lead to a “SIGKILL” in one of the rows marks 1, 2, 3

I really don’t understand why

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Article *article = [articles objectAtIndex:indexPath.row];
    ArticleCell *cell = (ArticleCell*)[self.tableView dequeueReusableCellWithIdentifier:@"articelcell"];

    if (cell == nil) 
    {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"ExtendibleCell" owner:self options:nil] objectAtIndex:0];
    }

    //....  
    cell.articleName.text = [NSString stringWithFormat:@"%@",article.name ];
    return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if ([searchBar isFirstResponder]) {
        [searchBar resignFirstResponder];
    }

    [orderTableDelegate receiveSelectedArticleName:[[articles objectAtIndex:indexPath.row] name]];
    firstSelected = lastSelected;
    lastSelected = indexPath;
    if (lastSelected == firstSelected && firstSelected != nil) {

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:lastSelected] withRowAnimation:CELL_ANIMATION]; //1
        lastSelected = nil;
        firstSelected = nil;
        return;
    }

    if (lastSelected != nil) {
        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:CELL_ANIMATION];//2
    }

    if (firstSelected != nil) {
        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:firstSelected] withRowAnimation:CELL_ANIMATION];//3
    }
}



-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section ==0) {
        if (searchBar == nil) {
            searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
            [searchBar setShowsBookmarkButton:YES];
            [searchBar setKeyboardType:UIKeyboardTypeAlphabet];
            [searchBar setBarStyle:UIBarStyleBlack];
            [searchBar setShowsCancelButton:YES];
            [searchBar setDelegate:self];
        }
        return searchBar;
    }
    return nil;
}


-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([indexPath isEqual:lastSelected] && lastSelected!=firstSelected) {
        return [[(Article *)[articles objectAtIndex:indexPath.row] sizesAndPrices] count]*PACKAGESIZE_PRICE_BUTTON_HEIGHT +30;
    }
    return 40.0;
}

edit
I cleaned up my code for -tableView:didSelectRowAtIndexPath:, but the problem stays the same

@property(nonatomic,retain) NSIndexPath *firstSelected;
@property(nonatomic,retain) NSIndexPath *lastSelected;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    [orderTableDelegate receiveSelectedArticleName:[[articles objectAtIndex:indexPath.row] name]];
    self.firstSelected = nil;
    self.firstSelected = self.lastSelected;
    self.lastSelected = nil;
    self.lastSelected = [indexPath retain];

    if (self.firstSelected == self.lastSelected) {
        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:self.firstSelected] withRowAnimation:CELL_ANIMATION];
        [self.firstSelected release];
        [self.lastSelected release];
        self.firstSelected = nil ;
        self.lastSelected = nil ;
    } else {
        if (self.firstSelected != nil) {

            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:self.firstSelected] withRowAnimation:CELL_ANIMATION];

        }

        if (self.lastSelected != nil) {

            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:self.lastSelected] withRowAnimation:CELL_ANIMATION];


        }
    }


    if ([searchBar isFirstResponder]) {
        [searchBar resignFirstResponder];
    }
}
  • 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-16T11:48:16+00:00Added an answer on May 16, 2026 at 11:48 am
       firstSelected = lastSelected;
        lastSelected = indexPath;
    

    This leads me to believe that lastSelected is an instance variable? If this is the case, you are not properly retaining it, and there is no guarantee that it is still alive beyond the scope of this method. The indexPath passed in the didSelectRowAtIndexPath: argument needs to be retained if you are going to use it after it’s execution.

    Keep in mind, if you do that, you need better memory management throughout that method…i.e. releasing lastSelected before changing it’s value or setting it to nil.

    Assuming firstSelected and lastSelected are instance variables, you could do something like this. (all the releasing and != checking would go away if you made them retained properties and used the setter)

    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        if ([searchBar isFirstResponder]) {
            [searchBar resignFirstResponder];
        }
    
        [orderTableDelegate receiveSelectedArticleName:[[articles objectAtIndex:indexPath.row] name]];
    
        if (firstSelected != lastSelected) {
            [firstSelected release];
            firstSelected = [lastSelected retain];
        }
    
        if (lastSelected != lastSelected) {
            [lastSelected release];
            lastSelected = [indexPath retain];
        }
    
        if (lastSelected == firstSelected && firstSelected != nil) {
    
            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:lastSelected] withRowAnimation:CELL_ANIMATION]; //1
            [lastSelected release];
            lastSelected = nil;
            [firstSelected release];
            firstSelected = nil;
            return;
        }
    
        if (lastSelected != nil) {
            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:CELL_ANIMATION];//2
        }
    
        if (firstSelected != nil) {
            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:firstSelected] withRowAnimation:CELL_ANIMATION];//3
        }
    }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

guys. I have UITableView with different cells and I have code, which counts height.
I have UITableView with images as rows (cells). I use EGOImageView to load images
I have UITableView with very large cells with lots of content (more than one
I have a UITableView that lists comments from various users. I save all of
I have a UITableView with some custom cells in it. In these custom cells
I have a UITableView that I have set-up with 2 sections. The code below
I have a UItableView I can add and delete cells. I can change the
I have UITableView with Static cells. I control-drag from one of these static cells
I have UITableView which contains cells. what I would like to do once user
I have UITableView with cells. Cell contains image, label and detail label. Then I've

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.