Advertise Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-10-2010, 07:25 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 8
Default view name from array?

Hi guys,
I just started with iPhone Development so don't be too hard on me.

So in my first view I have this:

in the .h:
Code:
NSArray *listOfDocs;
in the .m:
Code:
- (void)viewDidLoad {
	NSString *documentsDirectory = [NSHomeDirectory() 
					  stringByAppendingPathComponent:@"Documents"];
	
	NSError *error = nil;
	listOfDocs = [[NSFileManager defaultManager]
					 contentsOfDirectoryAtPath:documentsDirectory error:&error];
	
	self.navigationItem.title = @"Documents";
	self.navigationItem.rightBarButtonItem = self.editButtonItem;
	
	[super viewDidLoad];
}
That grabs the contents of the documents directory and puts them into an array.

Now I want to display the array in my navigation view... so I do this:
Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return[listOfDocs count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
	
	// Configure the cell.
	NSString *cellValue =[listOfDocs objectAtIndex:indexPath.row];
	cell.textLabel.text = cellValue;
	
	[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];

    return cell;
}
So far that works! But now I want to load a new view and have the name of the view be the name of the item clicked on. So I try this:

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

	EditViewController *editView = [[EditViewController alloc] initWithNibName:@"EditViewController" bundle:nil];
	[editView setTitle:[listOfDocs objectAtIndex:indexPath.row]];
	// editView.title = @"name";
	[self.navigationController pushViewController:editView animated:YES];
}
That crashes the app with a "EXC_BAD_ACCESS"
when I comment out
Code:
[editView setTitle:[listOfDocs objectAtIndex:indexPath.row]];
it runs fine, the name just does not change.

I'm not sure what I am doing wrong.. can someone help please?

Thanks
bluefire66 is offline   Reply With Quote
Old 02-10-2010, 07:57 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 110
Default

That crashes the app with a "EXC_BAD_ACCESS"
when I comment out
Code:
[editView setTitle:[listOfDocs objectAtIndex:indexPath.row]];
it runs fine, the name just does not change.

I'm not sure what I am doing wrong.. can someone help please?

Thanks[/quote]

Hi,

I do not have a solution - but it seems that I have the same problem. May you can set a breakpoint on the point where the app is crashing (when you try to objectAtIndex:X) - If it is of type "NSCFString" then we have the same issue...

Do you have a property of "setTitle" in the .h of the new View? Did you made @synth...?

BR,

Stefan

Last edited by StefanL; 02-10-2010 at 08:04 AM.
StefanL is offline   Reply With Quote
Old 02-10-2010, 08:39 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 8
Default

Quote:
Originally Posted by StefanL View Post
Do you have a property of "setTitle" in the .h of the new View? Did you made @synth...?
what is a @synth?
bluefire66 is offline   Reply With Quote
Old 02-10-2010, 08:52 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 110
Default

Quote:
Originally Posted by bluefire66 View Post
what is a @synth?
Sorry - @synthesize
StefanL is offline   Reply With Quote
Old 02-10-2010, 09:08 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 8
Default

yeah... got those.....
bluefire66 is offline   Reply With Quote
Reply

Bookmarks

Tags
array, navigation, string, view

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Online Users: 381
24 members and 357 guests
AdamSubach, anonymous@, benoitr007, bensj, Danneman, Duncan C, gtyt38, gustavo7sexton, HemiMG, Jeremy1026, lifeCoder45, maxus182, mox, Ovidius, Paul10, pofak, raheel, Sega dude, squidboy, timle8n1, ufbobbo, ultrayard077
Most users ever online was 965, 06-30-2010 at 04:26 AM.
» Stats
Members: 41,860
Threads: 49,768
Posts: 213,052
Top Poster: BrianSlick (3,138)
Welcome to our newest member, gustavo7sexton
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:52 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0