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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

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 12-05-2010, 01:16 AM   #1 (permalink)
Pointless Programmer
 
Join Date: Feb 2009
Location: New Hampshire, US
Age: 19
Posts: 45
jlegend is on a distinguished road
Send a message via MSN to jlegend
Default Setting navigation bar title to cell text

I want to be able to get the navigation bar's title to be set to the cell title of what they selected. Here is what I have, but does not seem to be working.

Code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
	
	if(stbView == nil)
		stbView = [[SelectionsTabBarView alloc] initWithNibName:@"SelectionsTabBarView" bundle:nil];
	
	if(addNavigationController == nil)
		addNavigationController = [[UINavigationController alloc] initWithRootViewController:stbView];
		self.navigationController.title = cell.text;

	
	
	[self.navigationController presentModalViewController:addNavigationController animated:YES];
}
Thanks in advance
__________________
Learn Objective-C, C++ has std's.

My Site
jlegend is offline   Reply With Quote
Old 12-05-2010, 01:43 AM   #2 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Wow wa woo waaa!!!! Your all screwed up... First of all why are you allocating table cells in the didselectcell method? Your mixing that up with cellforrow...

Your making a new cell so the cell.text is nil.

You have two options:
1. Grab the text from the your tableview datasource(nsmutablearray, nsarray...etc.)
2. Grab the actuall selected cell using cellforindexpath (I think that's what it is called, look up UITAbleview methods you'll see it). Then use the text property and set the title of the nav
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 12-05-2010, 04:09 AM   #3 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

Firstly you need to declare what the cell is:

Code:
UITableViewCell *cell;
cell = [tableView cellForRowAtIndexPath:indexPath];
Once you have declared the cell you can then get the cell's text label as you would usually do, and then you would just need to set the navigation bar's label text to the cell's text.

Code:
 self.title = cell.textLabel.text;
Quote:
Originally Posted by jlegend View Post
I want to be able to get the navigation bar's title to be set to the cell title of what they selected. Here is what I have, but does not seem to be working.

Code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
	
	if(stbView == nil)
		stbView = [[SelectionsTabBarView alloc] initWithNibName:@"SelectionsTabBarView" bundle:nil];
	
	if(addNavigationController == nil)
		addNavigationController = [[UINavigationController alloc] initWithRootViewController:stbView];
		self.navigationController.title = cell.text;

	
	
	[self.navigationController presentModalViewController:addNavigationController animated:YES];
}
Thanks in advance
iSDK is offline   Reply With Quote
Old 12-05-2010, 04:59 AM   #4 (permalink)
Pointless Programmer
 
Join Date: Feb 2009
Location: New Hampshire, US
Age: 19
Posts: 45
jlegend is on a distinguished road
Send a message via MSN to jlegend
Default

Here is what I have down so far. I want the Nav Bar that is coming up in the second view to display the cell text. It does not work.

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	UITableViewCell *cell;
	cell = [tableView cellForRowAtIndexPath:indexPath];
	
	if(stbView == nil)
		stbView = [[SelectionsTabBarView alloc] initWithNibName:@"SelectionsTabBarView" bundle:nil];
	
	if(addNavigationController == nil)
		addNavigationController = [[UINavigationController alloc] initWithRootViewController:stbView];

	[self.navigationController presentModalViewController:addNavigationController animated:YES];
	addNavigationController.title = cell.text;
}
__________________
Learn Objective-C, C++ has std's.

My Site
jlegend is offline   Reply With Quote
Old 12-05-2010, 06:52 AM   #5 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

The first thing that jumped out at me was this:

Quote:
Originally Posted by jlegend View Post
Code:
	addNavigationController.title = cell.text;
Surely you are getting a warning with this??

its cell.textLabel.text.
iSDK is offline   Reply With Quote
Old 12-05-2010, 07:00 AM   #6 (permalink)
Pointless Programmer
 
Join Date: Feb 2009
Location: New Hampshire, US
Age: 19
Posts: 45
jlegend is on a distinguished road
Send a message via MSN to jlegend
Default

It still is not working. Here is my cellForRowAtIndexPath and didSelectRowAtIndexPath.

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
	
	//Get the object from the array.
	Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:indexPath.row];
	
	//Set the coffename.
	cell.text = coffeeObj.coffeeName;
    
    // Set up the cell
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	UITableViewCell *cell;
	cell = [tableView cellForRowAtIndexPath:indexPath];
	
	if(stbView == nil)
		stbView = [[SelectionsTabBarView alloc] initWithNibName:@"SelectionsTabBarView" bundle:nil];
	
	if(addNavigationController == nil)
		addNavigationController = [[UINavigationController alloc] initWithRootViewController:stbView];

	[self.navigationController presentModalViewController:addNavigationController animated:YES];
	addNavigationController.title = cell.textLabel.text;
}
__________________
Learn Objective-C, C++ has std's.

My Site
jlegend is offline   Reply With Quote
Old 12-05-2010, 02:32 PM   #7 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Try setting the title of the stbView instead.

stbView.title= cell.text;

P.s. Cell.text is depricated...
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 12-05-2010, 03:09 PM   #8 (permalink)
Pointless Programmer
 
Join Date: Feb 2009
Location: New Hampshire, US
Age: 19
Posts: 45
jlegend is on a distinguished road
Send a message via MSN to jlegend
Default

Quote:
Originally Posted by Bertrand21 View Post
Try setting the title of the stbView instead.

stbView.title= cell.text;

P.s. Cell.text is depricated...
Thank you! It worked. Thank you as well iSDK. Both of your help is very much appreciated.
__________________
Learn Objective-C, C++ has std's.

My Site
jlegend is offline   Reply With Quote
Reply

Bookmarks

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: 378
6 members and 372 guests
chemistry, daudrizek, HemiMG, jeroenkeij, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:54 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0