About loading plist into navigator

Discussion in 'iOS Programming' started by MynEz, Jan 13, 2011.

  1. macrumors newbie

    Joined:
    Jan 13, 2011
    Location:
    Regina,Sask
    #1
    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
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
  3. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #3
  4. thread starter macrumors newbie

    Joined:
    Jan 13, 2011
    Location:
    Regina,Sask
    #4
    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. - -"
     
  5. dejo, Jan 13, 2011
    Last edited: Jan 14, 2011

    Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    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