Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread Display Modes
Old Jan 13, 2011, 03:52 PM   #1
macrumors newbie
Join Date: Jan 2011
Location: Regina,Sask
About loading plist into navigator


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
MynEz is offline   0 Reply With Quote
Old Jan 13, 2011, 04:20 PM   #2
robbieduncan's Avatar
Join Date: Jul 2002
Location: London
You are releasing an object you don't own. Read the (and understand) the Memory Management Guide.
robbieduncan is offline   0 Reply With Quote
Old Jan 13, 2011, 04:25 PM   #3
balamw's Avatar
Join Date: Aug 2005
Location: New England, USA
Please read the sticky thread about the use of the CODE tags. Your code is now mangled.

MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Jan 13, 2011, 10:16 PM   #4
Thread Starter
macrumors newbie
Join Date: Jan 2011
Location: Regina,Sask
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. - -"
MynEz is offline   0 Reply With Quote
Old Jan 14, 2011, 12:57 AM   #5
dejo's Avatar
Join Date: Sep 2004
Location: The Centennial State
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 by dejo; Jan 14, 2011 at 08:41 AM. Reason: Added P.S.
dejo is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
A problem loading from a local XML in UITabBarController micharadi iPhone/iPad Programming 0 Nov 14, 2011 05:19 AM
Reading plist into array of dictionaries help teengohan iPhone/iPad Programming 6 May 21, 2011 11:12 AM
Copy plist into the Documents Sergio10 iPhone/iPad Programming 1 Sep 29, 2009 06:53 AM
Safari history.plist into Tabs.. :confused: Eazkk123 Mac Applications and Mac App Store 0 Nov 25, 2008 12:09 PM

All times are GMT -5. The time now is 02:15 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013,, LLC