Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS XML Parsing, display results on table view and pushing to a new tableview
    primarykey
    data
    text
    <p>The goal of my application is to parse some XML, display one element of the xml in a tableview and then have the user click on the cell, and it pushes to a new table view where the rest of the data for that element is displayed. The first table view that displays only the list works fine, but for some reason I can't get the push to a new view controller to work. Below is the code I am using. The first view controller displays in a table view; currentCallType. I wan the user to be be able to click on that table cell, then push to a new table view where it displays the units, station and location. Any help would be AWESOME! thanks. </p> <p><strong>View controller for first tableview:</strong></p> <pre><code>#import "ThirdViewController.h" #import "UnitsXMLParser.h" #import "DetailViewController" @implementation ThirdViewController @synthesize unitsTableView; @synthesize currentCallType, station, location, units; XMLParser1 *xmlParser; - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - #pragma mark Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [[xmlParser units] count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; Units *currentCall = [[xmlParser units] objectAtIndex:indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // Set up the cell... cell.textLabel.text = [currentCall currentCallType]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 55; } #pragma mark - #pragma mark Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"detail"]; [self.navigationController pushViewController:detail animated:YES]; } #pragma mark - View lifecycle - (void)viewDidLoad { [super viewDidLoad]; xmlParser = [[XMLParser1 alloc] loadXMLByURL:@"http://localhost:8888/units.xml"]; } </code></pre> <p><strong>XML Parser:</strong></p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import "UnitsXMLParser.h" @implementation XMLParser1 @synthesize units = _units; NSMutableString *currentNodeContent; NSXMLParser *parser; Units *currentCall; bool isStatus; -(id) loadXMLByURL:(NSString *)urlString { _units = [[NSMutableArray alloc] init]; NSURL *url = [NSURL URLWithString:urlString]; NSData *data = [[NSData alloc] initWithContentsOfURL:url]; parser = [[NSXMLParser alloc] initWithData:data]; parser.delegate = self; [parser parse]; return self; } - (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { currentNodeContent = (NSMutableString *) [string stringByReplacingOccurrencesOfString:@"~" withString:@""]; } - (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementname isEqualToString:@"station"]) { currentCall = [Units alloc]; isStatus = YES; } } - (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName { if (isStatus) { if ([elementname isEqualToString:@"units"]) { currentCall.units = currentNodeContent; } if ([elementname isEqualToString:@"name"]) { currentCall.currentCallType = currentNodeContent; } if ([elementname isEqualToString:@"stationid"]) { currentCall.station = currentNodeContent; } if ([elementname isEqualToString:@"address"]) { currentCall.location = currentNodeContent; } } if ([elementname isEqualToString:@"station"]) { [self.units addObject:currentCall]; currentCall = nil; currentNodeContent = nil; } } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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