Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MynEz

macrumors newbie
Original poster
Jan 13, 2011
13
0
Regina,Sask
Hello

I'm beginner of X-code, now i'm trying to load the data from plist file into navigator but it didn't work well. When application is run, I can see my data from plist but it's not too long because the app. will close itself (I could not slide up and down to fast too ). I don't know why and I tried to release the array but it didn't work, I couldn't access to see the data. If somebody knows how to solve this o, please tell me. Many thanks

Here is my code

NSString *path = [[NSBundle mainBundle]pathForResource:mad:"statedictionary1" ofType:mad:"plist"];
NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFileath];
self.keys = dict;
[dict release];

NSArray *array = [[keys allKeys]sortedArrayUsingSelector:mad:selector(compare];
self.list = array;

I couldn't release the array because my app will get crashed. I don't know why
 
Thank you for your reply

@robbieduncan : I didn't get it yet, but I 've fixed my code now. I can release the array and it works though. There's still one problem, when I scroll up or down quickly or sometimes just scrolling down or up, the application still closed itself. Did I do something wrong? :( or could you tell me how to fix the code?

Code:
-(void)viewDidLoad{
	NSString *path = [[NSBundle mainBundle]pathForResource:@"statedictionary1" ofType:@"plist"];
	NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:path];
	self.keys = dict;
	[dict release];
		
	NSArray *array = [[NSArray alloc] init];
	[array release];				  
	array = [[keys allKeys]sortedArrayUsingSelector:@selector(compare:)];
	
	self.list = array;
	
	
	[super viewDidLoad];
}[/B]

-(void)viewDidUnload{

	self.list = nil;
	
	[super viewDidUnload];
}

-(void)didReceiveMemoryWarning{
	self.list =nil;
	[super didReceiveMemoryWarning];
}

-(void)dealloc{
	[super dealloc];
	[list release];
	[keys release];
	[childController release];

}

[B]-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	
	return [self.list count];
}[/B]

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

	NSString *button = @"Sunday";
	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:button];
	
	if(cell == nil){
		cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:button]autorelease];
		
	}
	NSUInteger row = [indexPath row];
	NSString *rowString = [list objectAtIndex:row];
	cell.textLabel.text = rowString;
	cell.textLabel.font = [UIFont systemFontOfSize:15];
	cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
	[rowString release];
	return cell;

}

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
	if (childController == nil)
		childController = [[DetailSecond alloc]initWithNibName:@"DetailSecond" bundle:nil ];
	childController.title = @"SundayZ";
	NSUInteger row = [indexPath row];
	
	NSString *selectedR = [list objectAtIndex:row];
	NSString *details = [[NSString alloc]initWithFormat:@"You press %@", selectedR];
	childController.message = details;
	childController.title = selectedR;
	[details release];
	[self.navigationController pushViewController:childController animated:YES];
}

@balamw I'm sorry, I apologize, I've just registered half a day. - -"
 
You can't release rowString either. Have you read the Memory Management Guide yet?

P.S. There's also a problem with the order of things in your dealloc.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.