Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ataylor2009

macrumors member
Original poster
Jan 27, 2009
78
0
Okay, I know this question has an easy answer, but I'll be damned if I can figure it out...and I'm all out of clever search terms for the developer docs, but I know I'm close.

I have a table view, and upon selecting a detail disclosure button, my user is presented with a new view. I'd like to set the new view's title to the selected cell's textLabel property like "ruleViewerController.title = ??"

Can someone please put me out of my misery here? I know this isn't that hard, and I'll bet when I get the answer that it turns out to be on a page in the developer docs that I currently have open in another tab on my browser, but like I said - I'm currently stumped.

Thanks in advance.
 
Lets say you are tying an array to the table. If you click on a cell it should tell you which one was clicked and then you go to your data source and get that item.
 
Here's the code in question:

Code:
-(void)tableView:(UITableView*)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath*)indexPath {
RuleViewController *ruleViewController = [[RuleViewController alloc] initWithNibName:@"RuleViewController" bundle:nil];
ruleViewController.title = @"Julie"; // this is what I need to make dynamic
[self.navigationController pushViewController:ruleViewController animated:YES];
[ruleViewController release];
}

The commented line in the middle is the part I need help with; how do I get the selected cell's "textLabel" property, given only the indexPath? Like I said, I'm sure the solution is simple, but I'm still stumped.
 
Okay, I got it. Solution was

Code:
UITableCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
NSString *cellTitle = cell.textLabel.text;
ruleViewController.title = cellTitle;
// push controller

One step closer to done...one more item crossed off the to-do list.
 
Wirelessly posted (Mozilla/5.0 (iPod; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16)

The accepted approach is to pull the info from the same data source that was used to populate the cell in the first place.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.