View Full Version : About loading plist into navigator

Jan 13, 2011, 03:52 PM

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:@"statedictionary1" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFileath];
self.keys = dict;
[dict release];

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

I couldn't release the array because my app will get crashed. I don't know why

Jan 13, 2011, 04:20 PM
You are releasing an object you don't own. Read the (and understand) the Memory Management Guide (http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/MemoryMgmt/MemoryMgmt.html).

Jan 13, 2011, 04:25 PM
Please read the sticky thread about the use of the CODE tags. http://forums.macrumors.com/showthread.php?t=747660. Your code is now mangled.


Jan 13, 2011, 10:16 PM
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?

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];


self.list = nil;

[super viewDidUnload];

self.list =nil;
[super didReceiveMemoryWarning];

[super dealloc];
[list release];
[keys release];
[childController release];


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return [self.list count];

-(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. - -"

Jan 14, 2011, 12:57 AM
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.