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

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 02-10-2010, 08:25 AM   #1 (permalink)
bluefire66
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
 

» Advertisements
» Stats
Members: 158,860
Threads: 89,223
Posts: 380,683
Top Poster: BrianSlick (7,129)
Welcome to our newest member, randybourassa
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.