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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:38:45+00:00 2026-05-21T05:38:45+00:00

So basically I am trying to create instances of the class below every time

  • 0

So basically I am trying to create instances of the class below every time I received a valid response from a web request and then store those instances in an array so I can access their data later. Then, I try to populate a table view with specific fields from the instance(s) that are stored in the array. I’ve been having some issues since I am very familiar with C++ and do this sort of thing with vectors and then just access based off of the index I need, but this has had me pulling my hair out! Thanks, code is below:

eventDetails.h:

@interface eventDetails : NSObject {
NSString *eventName, *eventID;
}

-(void) setEventID : (NSString *) ID;
-(void) setEventName: (NSString *) name;
-(NSString *) getEventName;
-(NSString *) getEventID;

and also note that

 NSMutableArray *events

is declared in my .h file and

 events = [[NSMutableArray alloc] init]; 

has been called in the viewDidLoad

I then dynamically create instances as a response is received from an web request and add them to an array:

if ([elementName isEqualToString:@"id"])
{
    NSLog(@"at beginning of event, length is %i", [events count]);
    temp = [[eventDetails alloc] init];
    [temp setEventID:[NSMutableString stringWithString:soapResults]];

    [soapResults setString:@""];
    elementFound = FALSE; 
}

if ([elementName isEqualToString:@"name"])
{

    [temp setEventName:[NSMutableString stringWithString:soapResults]];
    [events addObject:temp];
    [soapResults setString:@""];
    elementFound = FALSE; 
    //[temp release];

}

After everything is all said and done, I created a little test function to ensure the data was set correctly:

-(void) test{
for (eventDetails *s in events){
    NSLog(@"Entry ID: %@ with name %@", [s getEventID], [s getEventName]);
 }
}

and I get the following (correct) output:

2011-04-09 18:53:24.624 Validator[90982:207] Entry ID: 701 with name iPhone Test Event
2011-04-09 18:53:24.625 Validator[90982:207] Entry ID: 784 with name Another iPhone Test Event
2011-04-09 18:53:24.626 Validator[90982:207] Entry ID: 839 with name third iphone

I then try to refresh the table view, and have it pull in data from the instances in the array:

 // Customize the appearance of table view cells.
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
//---try to get a reusable cell---
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//---create new cell if no reusable cell is available---
if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                                  reuseIdentifier:CellIdentifier] autorelease];
}
//---set the text to display for the cell---
eventDetails *cellDetails = [[eventDetails alloc] init];
NSInteger row = [indexPath row];
cellDetails = [[self events] objectAtIndex:row];

NSString *cellValue = [cellDetails getEventName];
NSLog(@"Event is: %@", cellValue);
cell.textLabel.text = cellValue;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;

}

But every time the program gets to this part, it crashed which a EXC_BAD_ACCESS where I say:

 cell.textLabel.text = cellValue;

Thanks for your help. I think I might be doing something wrong with how I declare the instances of the eventDetails class, but I am not sure since it is working correctly as far as storing that data. If you need any more code, I have the missing sections.

  • 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-21T05:38:45+00:00Added an answer on May 21, 2026 at 5:38 am

    There are too many omitted details in the code you posted to know for sure, but my guess would be the eventName isn’t retained, and is deallocated sometime before you attempt to use it.

    Check your setEventName: implementation; it would need to send either retain or copy to the name argument to ensure that the string won’t be deallocated before you’re done using it. However, the situation is more complex than that if you want to avoid memory leaks, so you if you haven’t done so already, I’d recommend reading up on memory management, in particular, Apple’s excellent Memory Management Programming Guide. (Note: I’ve given up posting links since Apple keeps changing them).

    A side note: don’t prefix the names of accessor methods with the word get; that would be fine in Java or C++, but this is Objective-C. Your accessors should look like this:

    - (NSString *)eventName;
    - (NSString *)eventID;
    

    There’s no guarantee that Foundation mechanisms that rely on introspection will work correctly with accessors that don’t follow the documented naming conventions, so that’s another thing to read up on. 🙂

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

Sidebar

Related Questions

Basically, what I am trying to do is to create a Singleton instance of
I'm basically trying to create a url friendly query string with user input. The
I'm basically trying to create a 2 column div with a liquid <h1> and
im stuck with a problem im basically trying to create a function where I
Basically I'm trying to create a BASIC sorting program in ruby without using .sort
Basically I'm trying to create an implementation of simulated annealing for the multidimensional knapsack
I am trying to create something in Perl that is basically like the Unix
I am trying to create a rule for snort to basically log any packets
I'm trying to create a .vcs file in C#. Basically in outlook if you
I'm trying to create a kind of file generator in Php. Basically, it get

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.