Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems Populating TableView with NSMutableArray
    text
    copied!<p>I'm using SudzC for an iPhone app. I'm succesfully calling my ASP.Net webservice and pulling the needed data into an NSMutable array called tableData. I have a tableView that should display the contents of tableData; however this is not working. I've looked for hours at this problem. I'm very new to the Objective C world so I'm thinking it's a small oversight on my part. I've linked my TableView to the ViewController (delegate/datasource) as well.</p> <p>Here's is the code I have:</p> <pre><code>#import "ViewController.h" #import "DocumentServiceJSONService.h" @interface ViewController () @end @implementation ViewController NSMutableArray *tableData; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } -(void)viewWillAppear:(BOOL) animated { tableData = [[NSMutableArray alloc] init]; DocumentServiceJSONService* service = [[DocumentServiceJSONService alloc] init]; [service GetAllEMSDocumentsXMLAsString: self action:@selector(handleGetAllEMSDocuments:)]; [super viewWillAppear:animated]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void) handleGetAllEMSDocuments:(id) result { if ([result isKindOfClass:[NSError class]]) { //if an error has occurred, handle it return; } if([result isKindOfClass: [SoapFault class]]) { return; } NSString* xmlString = result; CXMLDocument *xmlDoc = [[CXMLDocument alloc] initWithXMLString:xmlString options:0 error:nil]; NSArray *nodes = NULL; nodes = [xmlDoc nodesForXPath:@"//EMSDocuments" error:nil]; for (CXMLElement *node in nodes) { NSMutableDictionary *item = [[NSMutableDictionary alloc] init]; int counter; for (counter = 0; counter &lt; [node childCount]; counter++) { [item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]]; } //[item setObject:[[node attributeForName:@"DisplayName"] stringValue] forKey:@"DisplayName"]; NSString *displayName = [item objectForKey:@"DisplayName"]; [tableData addObject:displayName]; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [tableData count]; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; } cell.textLabel.text = [tableData objectAtIndex:indexPath.row]; return cell; } @end </code></pre> <p>Any advice is appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload