12-05-2010, 01:16 AM
#1 (permalink )
Pointless Programmer
Join Date: Feb 2009
Location: New Hampshire, US
Age: 19
Posts: 45
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
12-05-2010, 01:43 AM
#2 (permalink )
Beast Mode
Join Date: Dec 2008
Age: 21
Posts: 1,971
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
12-05-2010, 04:09 AM
#3 (permalink )
Indie Developer
Join Date: Jul 2010
Posts: 1,346
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
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
12-05-2010, 04:59 AM
#4 (permalink )
Pointless Programmer
Join Date: Feb 2009
Location: New Hampshire, US
Age: 19
Posts: 45
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
12-05-2010, 06:52 AM
#5 (permalink )
Indie Developer
Join Date: Jul 2010
Posts: 1,346
The first thing that jumped out at me was this:
Quote:
Originally Posted by
jlegend
Code:
addNavigationController.title = cell.text;
Surely you are getting a warning with this??
its cell.textLabel.text.
12-05-2010, 07:00 AM
#6 (permalink )
Pointless Programmer
Join Date: Feb 2009
Location: New Hampshire, US
Age: 19
Posts: 45
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
12-05-2010, 02:32 PM
#7 (permalink )
Beast Mode
Join Date: Dec 2008
Age: 21
Posts: 1,971
Try setting the title of the stbView instead.
stbView.title= cell.text;
P.s. Cell.text is depricated...
__________________
Haters gonna Hate
Likers gonna Like
12-05-2010, 03:09 PM
#8 (permalink )
Pointless Programmer
Join Date: Feb 2009
Location: New Hampshire, US
Age: 19
Posts: 45
Quote:
Originally Posted by
Bertrand21
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
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek