user875293
user875293

Reputation: 679

Nothing Happens When didSelectRowAtIndexPath on table view

I have a table view and when i select one of the items it should go to my EventsDetailsViewController storyboard for displaying details but nothing happens when i click one of the itmes in my table view. Below is the code i thought would send a user to the EventsDetailsViewController when selected but doesn't.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    EventsDetailsViewController *eventsdetailsViewController = [[EventsDetailsViewController alloc]
    initWithNibName:@"EventsDetailsViewController" bundle:nil];
    eventsdetailsViewController.title = [[events objectAtIndex:indexPath.row] objectForKey:@"eName"];
    eventsdetailsViewController.eventsArticle = [events objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:eventsdetailsViewController animated:YES];

}

Upvotes: 0

Views: 113

Answers (2)

Prashant Nikam
Prashant Nikam

Reputation: 2251

Its not the problem of tableView, the problem is in navigationController, check whether it is nil or something in debug area If it is nil then initialize it.

Hope this will help you.

EDIT : How to Declare NavigationController

Add this to AppDelegate.m file

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    ParentViewController *parent = [[ParentViewController alloc]init];
    UINavigationController *myNav = [[UINavigationController alloc]initWithRootViewController:parent];
    self.window.rootViewController = myNav;
    [self.window makeKeyAndVisible];
    return YES;
}

Upvotes: 0

RK-
RK-

Reputation: 12201

The possible problems could be:

  1. Your application is not navigation controller based. Just check if you have created a navigation controller through Xib, storyboard, or programatically.

  2. Your EventsDetailsViewController is not at all created. Have a break point or log the object and test if this is created or just nil.

You can easily verify both the cases by using the below statements:

NSLog("Navigation COntroller %@",self.navigationController);
NSLog("Events COntroller %@", eventsdetailsViewController);

Let us assume ABCController is the controller in which the table view delegate methods are present and from there you want to move to the EventsDetailsViewController. Adding navigation controller to your existing project:

Create a navigation controller object in your app delegate and set this as rootViewController

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:rootController];
self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
 return YES;
}

Upvotes: 1

Related Questions