Note that there are some explanatory texts on larger screens.

plurals
  1. PONSMutableArray vs NSArray Round 2
    text
    copied!<p>my question depends on my other question</p> <p><a href="https://stackoverflow.com/questions/6580076/nsmutablearray-vs-nsarray">NSMutableArray vs NSArray</a></p> <p>i have created a navigationController and load a TableView inside with data from the other question. Now a get a detailview and get new data from xml, so i copy my methods and modifide them.</p> <p>but it is the same stucture, i does not change a lot.</p> <p>But now i get the same error.</p> <p>i have in detailview.h</p> <pre><code> NSMutableArray *seminareArray; </code></pre> <p>and</p> <pre><code>@property (nonatomic, retain) NSMutableArray *seminareArray; </code></pre> <p>in detailview.m</p> <pre><code>@synthesize SeminareListeTabelle, selectedSeminar, seminareArray, receivedData; </code></pre> <p>i add this code</p> <pre><code>seminareArray = [[NSMutableArray alloc] init]; self.seminareArray = [NSMutableArray arrayWithCapacity:10]; </code></pre> <p>before i add the data. and i get the error here</p> <pre><code>cell.textLabel.text = [seminareArray objectAtIndex:row]; </code></pre> <p>EXC_BAD_ACCESS again some type problem</p> <p>i add data to array like this</p> <pre><code>if([elementName isEqualToString:@"seminar"]) { //NSLog(@"%@", [attributeDict objectForKey:@"name"]); NSString *seminarName = [NSString stringWithFormat:@"%@", [attributeDict objectForKey:@"name"]]; [seminareArray addObject:seminarName]; [seminarName release]; } </code></pre> <p>the array is filled with data, but after tableView reload, i get this error.</p> <pre><code>// // SeminareListingView.m // Seminar App2 // // Created by Alexander Frischbutter on 05.07.11. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import "SeminareListingView.h" //#import "SeminareView.h" @implementation SeminareListingView @synthesize SeminareListeTabelle, selectedSeminar, seminareArray, receivedData; - (void) parseData:(NSString *)url { if(receivedData) { receivedData = nil; } NSLog(@"Parsing... url: %@", url); NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", url]] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if(theConnection) { receivedData = [[NSMutableData data] retain]; } else { //label.text = @"XML nicht geladen"; NSLog(@"XML nicht gefunden"); } } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)dealloc { [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 - View lifecycle - (void)viewDidLoad { [super viewDidLoad]; SeminareListeTabelle = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain]; SeminareListeTabelle.delegate = self; SeminareListeTabelle.dataSource = self; SeminareListeTabelle.autoresizesSubviews = YES; seminareArray = [[NSMutableArray alloc] init]; self.seminareArray = [NSMutableArray arrayWithCapacity:10]; [self parseData:[NSString stringWithFormat:@"http://akademie.kunden.fincha.com/semapp/sem_kat_arbtechnik.xml", selectedSeminar]]; self.navigationItem.title = [NSString stringWithFormat:@"%@", selectedSeminar]; self.view = SeminareListeTabelle; // Do any additional setup after loading the view from its nib. } - (void)startParsingData { NSLog(@"Parsing started"); NSXMLParser *dataParser = [[NSXMLParser alloc] initWithData:receivedData]; dataParser.delegate = self; [dataParser parse]; [dataParser release]; [receivedData release]; NSLog(@"Received Data in seminareArray"); /* for(int i = 0; i &lt; [seminareArray count]; i++) { NSLog(@"%d is %@", i, [seminareArray objectAtIndex:i]); //NSLog(@"Count %d", [kategorienArray count]); } */ //[seminareArray release]; NSLog(@"Reload data in TableView"); [self.SeminareListeTabelle reloadData]; NSLog(@"Data reloaded"); } - (void)viewDidUnload { //[seminareArray release]; //[SeminareListeTabelle release]; NSLog(@"Vew unloaded"); [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SimpleTableIdentifier] autorelease]; } if([seminareArray count] != 0) { NSLog(@"Adding data to cell"); NSUInteger row = [indexPath row]; //cell.textLabel.text = [NSString stringWithFormat:@"bla, %d", row]; //[seminareArray objectAtIndex:row]; cell.textLabel.text = [seminareArray objectAtIndex:row]; NSLog(@"Added data to cell"); } return cell; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { //NSLog(@"Count %d", [self.seminareArray count]); return [seminareArray count]; } -(NSInteger) tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { return 0; } //Anzeige mit Seminaren öffnen bei Click auf die Zeile -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //gehe zurück zum ersten View //NSLog(@"Received Data in seminareArray"); [[self navigationController] popViewControllerAnimated:YES]; } - (void)connection:(NSURLConnection *)connection didReceiveResonse:(NSURLResponse *)response { [receivedData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { if(receivedData) { [receivedData appendData:data]; } } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { [connection release]; [receivedData release]; //label.text = @"Connection failed"; NSLog(@"Verbindung fehlgeschlagen!"); //[[self navigationController] popViewControllerAnimated:YES]; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { [self startParsingData]; [connection release]; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { //NSLog(@"Parser was called. Element: %@", elementName); if([elementName isEqualToString:@"seminar"]) { //NSLog(@"%@", [attributeDict objectForKey:@"name"]); NSString *seminarName = [NSString stringWithFormat:@"%@", [attributeDict objectForKey:@"name"]]; [seminareArray addObject:seminarName]; [seminarName release]; } } - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError { NSLog(@"Parse Error %@", parseError); } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end </code></pre>
 

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