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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:54:56+00:00 2026-05-20T00:54:56+00:00

Greetings, people. I’m diving into Objective-C for pretty much the first time. It’s kicking

  • 0

Greetings, people.

I’m diving into Objective-C for pretty much the first time. It’s kicking my C# butt, but (heh) I think I’m finally starting to “get” some of the concepts.

I’m writing an iPhone app that connects to a web service, pulls back data in XML format, parses the data, and renders it as a UITableView. Clicking a cell in the tableview loads a detail view, and so on.

I’m running into some conceptual problems. In C#, most controls have a display label and a value. Which makes it easy to attach events (another thing I am addicted to) to a cell or entry and key off the value for further look ups.

The problem I’m having is that the UITableView, whilst built for a detail view, doesn’t seem to have a value property or anything I can intelligently key off of to pass an identifier to the detail view and populate it.

Currently I am handling this by parsing my XML feed into an NSMutableArray that holds all of the data about a particular entry. I populate the UITableView based on one particular field in that array. And then I use objectAtIndex:indexPath.row to pass any identifiers or the like to the detail view.

I could proceed like this and get it working, but the whole thing feels like a big mess and like it’s going to be a monster to maintain/scale out. So, with that being said…please help me! I’m going to post a lot of my code so you can see just how poorly I’m approaching this 🙂

The Table View controller I’m horribly overtasking:

#import "InvoicesTableViewController.h"
#import "Wrapper.h"
#import "InvoiceDetailViewController.h"


@implementation InvoicesTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [listOfItems release];
    [restAPI release];
    [parameters release];

    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - Wrapper
- (void)wrapper:(Wrapper *)wrapper didRetrieveData:(NSData *)data
{
    NSData *result = [[restAPI responseAsText] dataUsingEncoding:NSUTF8StringEncoding];
    if (result != nil)
    {
        NSXMLParser *parser = [[[NSXMLParser alloc] initWithData:result] autorelease];
        parser.delegate = self;
        [parser parse];
    }
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

#pragma mark - Parser
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict 
{
    if(OneInvoice == nil)
    {
        OneInvoice = [[NSMutableArray alloc] init];
    }

    if ([elementName isEqualToString:@"invoice"]) 
    {
        [OneInvoice addObject:[attributeDict valueForKey:@"uri"]];
        [OneInvoice addObject:[attributeDict valueForKey:@"total"]];
        [OneInvoice addObject:[attributeDict valueForKey:@"total_due"]];
        [OneInvoice addObject:[attributeDict valueForKey:@"status"]];
    }

    if ([elementName isEqualToString:@"client"]) 
    {
        [OneInvoice addObject:[attributeDict valueForKey:@"name"]];
        [listOfItems addObject:[[NSMutableArray alloc] initWithArray:OneInvoice copyItems:YES]];

        [OneInvoice release];
        OneInvoice = nil;
        [self.tableView reloadData];
    }
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    listOfItems = [[NSMutableArray alloc] init];

    //Set the title
    self.navigationItem.title = @"Invoices";

    if(restAPI == nil) {
        restAPI = [[Wrapper alloc] init];
    }

    restAPI.delegate = self;

    parameters = nil;
    restAPI.mimeType = @"application/vnd.site+xml";

    url = [NSURL URLWithString: @"https://user:pass@site.com/invoices/?status=all"];
    [restAPI sendRequestTo:url usingVerb: @"GET" withParameters: parameters];


    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [listOfItems count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

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

    // Setup the cell
    NSString *cellValue = [NSString stringWithFormat:@"%@ - %@", [[listOfItems objectAtIndex:indexPath.row] objectAtIndex:4],[[listOfItems objectAtIndex:indexPath.row] objectAtIndex:1]];
    cell.textLabel.text = cellValue;

    return cell;
}

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {

    //return UITableViewCellAccessoryDetailDisclosureButton;
    return UITableViewCellAccessoryDetailDisclosureButton;
    //return UITableViewCellAccessoryDisclosureIndicator;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *invoiceURL = [[listOfItems objectAtIndex:indexPath.row] objectAtIndex:0];

    InvoiceDetailViewController *dvController = [[InvoiceDetailViewController alloc] initWithNibName:@"InvoiceDetailViewController" bundle:[NSBundle mainBundle]];
    dvController.invoiceURL = invoiceURL;
    [self.navigationController pushViewController:dvController animated:YES];
    [dvController release];
    dvController = nil;
}

@end

Please do not hesitate to mock my form. I am very inexperienced with C/C++, and particularly Objective-C. I hobbled this together last night to just get something working that I can build upon.

Thanks a million,
Clifton

  • 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-20T00:54:56+00:00Added an answer on May 20, 2026 at 12:54 am

    Cocoa uses the model-view-controller paradigm. In your case the model is the NSMutableArray, the controller the table view controller and the view your UITableView.
    Table cells do not hold any data. The controller will get notified when a cell is clicked and will figure out the corresponding data (like you did) and will then call another controller, update the model or update the views.

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

Sidebar

Related Questions

No related questions found

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.