About loading plist into navigator

Discussion in 'iPhone/iPad Programming' started by MynEz, Jan 13, 2011.

  1. macrumors newbie


    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
  2. Moderator


    Staff Member

  3. Moderator


    Staff Member

  4. macrumors newbie

    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];
    [B]-(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. - -"
  5. dejo, Jan 13, 2011
    Last edited: Jan 14, 2011



    Staff Member

    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.

Share This Page