Reputation: 175
Here is an exctract of on of my If statement in the table view delegate of ProfilTableViewController.m :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *currentCell =(UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
// Navigation logic may go here. Create and push another view controller.
if (currentCell.textLabel.text==@"phrase") {
MainViewController *phraseViewController =[[MainViewController alloc] initWithNibName:@"mesPhrase" bundle:nil];
[self.navigationController pushViewController:phraseViewController animated:YES];
}
On the storyboard I created a push from a cell of ProfilTVC to MainViewController and changed the TableViewController to "MainViewController"
When I run the app, clicking on a cell from ProfilViewController doesn't do anything :/ wtf?
cheers, Louis
Upvotes: 0
Views: 225
Reputation: 668
now all you have to do is to use prepareFor segue like follow:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure we're referring to the correct segue
if ([[segue identifier] isEqualToString:@"yourIdentifier"]) {
DestinationController *destination = [segue destinationViewController];
// get the selected index
NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
//now you can add informations you want to send to the new controller
//example:
destination.selectedItem=[myArray objectAtIndex:selectedIndex];
}
}
Don't forget to change the segue identifier: select the wire between the two controllers and set it in the attribute inspector on the right it has to be equal to youIdentifier
Upvotes: 0
Reputation: 31016
currentCell.textLabel.text==@"phrase"
compares the addresses of strings, not the content. Look at the isEqualToString:
method.
Upvotes: 1