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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:51:01+00:00 2026-05-26T20:51:01+00:00

I am trying to create a generic UITableView in my iPhone app. I have

  • 0

I am trying to create a generic UITableView in my iPhone app.
I have a UITableView which populates the data using an array via a SELECT query loop.
I add the data into my array and populate the array in cellForRowAtIndexPath:.
I get the section header using that array and by using a sort method, I put the section headers in Array1.

I would like to have titleForHeaderInSection: work by having section 0 be a static header name and sections 1 and later become generic, meaning the header name will come from Array1.

I am not sure how can I create that logic since the app always throws EXC_BAD_ACCESS with the code below.

My logic: I keep the count of the array in an int and see if the value is greater than 0. If it is, I add the section header for and objectAtIndex:0, otherwise I use the static one. But when the count gets to 2, for section 2 and objectAtIndex:1, it breaks and throws EXC_BAD_ACCESS.

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    int value = [[self Array1] count];
    if(section == 0)
        return @"Countries";

    if (value > 0) {
        if (section == value){
        return [[self Array1] objectAtIndex:section - 1];
    }
    }   
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    int count = [[self Array1] count];
    return count + 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section      
{
    int value = [[self Array1] count];
    if (section == 0) {
    return [self.Array count];
    }

    if (value > 0) {
        if (section == [[self Array1] count])  {
            NSString *initialLetter = [[self Array1] objectAtIndex:section - 1];

            // get the array of elements that begin with that letter
            NSArray *elementsWithInitialLetter = [self elementsWithInitialLetter:initialLetter];

            // return the count
            return [elementsWithInitialLetter count];
        }
    }

}
  • 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-26T20:51:01+00:00Added an answer on May 26, 2026 at 8:51 pm

    Looks like you’re just missing a retain on the iVar backing the Array1 method. declare the array as a property:

    @property (nonatomic, retain) NSArray* datastore;
    

    Then cache the value you’re referring to in the Array1 method in this method (probably in viewDidLoad).

    self.datastore = [self Array1];
    

    Then replace all remaining references to [self Array1] with self.datastore. Build run and see if it still crashes. (Don’t forget to set self.datastore = nil in your dealloc!

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

Sidebar

Related Questions

Using C++, I'm trying to create a generic container class to handle multiple data
I'm trying to create a generic class which will have some static functions based
I'm trying to create a generic graphics export tool which works by implementing the
I am trying to create a generic formatter/parser combination. Example scenario: I have a
I am trying to create a generic class which new's up an instance of
I'm trying to create an instance of a generic class using a Type object.
I am trying to create a generic method using EF4 to find the primary
I am trying to create a generic callback object that will hold arbitrary data
I'm trying to create a generic LINQ-TO-SQL repository based on this post which basically
I am currently trying to create a generic instance factory for which takes an

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.