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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:11:42+00:00 2026-05-28T03:11:42+00:00

I have a weird problem with the indexPath.section from the cellForRowAtIndexPath: method. I have

  • 0

I have a weird problem with the indexPath.section from the cellForRowAtIndexPath: method.

I have a grouped tableview with 4 sections and I’m trying to apply a custom UITableViewCell for section 3, but it’s not working.

When I try if(indexPath.section==0){...} it works (and for section==1 and section==2 as well) but it fails for section==3. (?)

I don’t know why, that makes no sense.. Did someone already had this (strange) problem?

When I try if(indexPath.row==0){...} it works for all the 4 sections.. so..?!

Here is my code :

//ViewController.h
import "DirectionsTableViewCell.h"
DirectionsTableViewCell *directionsCell; // customized UITableViewCell

//ViewController.m
if (indexPath.section==3) {
        static NSString *CellIdentifier = @"directionsCell";

        DirectionsTableViewCell *cell = (DirectionsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if(cell == nil) {
            [[NSBundle mainBundle] loadNibNamed:@"DirectionsTableViewCell" owner:self options:nil];
            cell = directionsCell;
        }

        return cell;
    }
    else {
        static NSString *CellIdentifier = @"defaultCell";

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

        cell.textLabel.text = @"Test";

        return cell;
    }

Problem solved !

I just added if(indexPath.row) and it works fine.

Finally you got this :

if(indexPath.section==3) {
   if(indexPath.row) {
      static NSString *CellIdentifier = @"directionsCell";

      DirectionsTableViewCell *cell = (DirectionsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if(cell == nil) {
          [[NSBundle mainBundle] loadNibNamed:@"DirectionsTableViewCell" owner:self options:nil];
          cell = directionsCell;
      }

      return cell;
   }
}
  • 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-28T03:11:43+00:00Added an answer on May 28, 2026 at 3:11 am

    Well, you’re never allocating a DirectionsTableViewCell inside your if(cell == nil).

    In this section of your code:

    DirectionsTableViewCell *cell = (DirectionsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if(cell == nil) {
                [[NSBundle mainBundle] loadNibNamed:@"DirectionsTableViewCell" owner:self options:nil];
                cell = directionsCell;
            }
    

    You never allocate a cell of type DirectionsTableViewCell for it to be reused later. I also notice you have an ivar named directionsCell of type DirectionsTableViewCell. Unless you’re allocating and setting it up elsewhere, cell = directionsCell ends up assigning a nil object to your cell

    Try this code instead and see if it works:

    static NSString *CellIdentifier = @"directionsCell";
    
    directionsCell = (DirectionsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if(directionsCell == nil) {
            directionsCell = [[DirectionsTableViewCell alloc] init]; //Or whatever your initializer is
        }
    
        return directionsCell;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing this very weird problem, I have created a custom UITableViewCell on
We have a weird intermittent problem with saving from Word 2007 to our SharePoint
I have some weird problem with templates. When trying to pass a parameterised iterator
I have a weird problem on my hand. I am trying to read an
i am experiencing some weird problems with my UITableView. I have a Grouped TableView
i have a weird problem. i would like to delete an assembly(plugin.dll on harddisk)
I have a weird problem with images in visual web developer, I cant change
I have a weird problem where after setting nocheck on a foreign constraint and
I have this weird problem with setting up cookies with PHP. Everything worked fine
I have a weird problem that i can't figure out a solution for: 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.