-3

I have the following code having capability such that, once I tap on the table cell it will go to another view controller where it has its description. I am trying to do it programmatically.

This is my code that controls the segue part, which is not getting called:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    DetailViewController *detailVC = (DetailViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"detailViewController"];
    detailVC.navigationItem.title = self.ourNumberOfQuotes[indexPath];
    detailVC.indexRow =  [NSString stringWithFormat:@"%@",indexPath];
    [self.navigationController pushViewController:detailVC animated:YES];

}

Why is this not getting called?

This is my .h file code

@interface QuoteTableViewController : UITableViewController <UIGestureRecognizerDelegate,UITableViewDataSource,UITableViewDelegate> {
    int i;
}
@property (strong, nonatomic) IBOutlet UIView *mainMenu;
@property (strong, nonatomic) IBOutlet UIButton *homeworkButton;
@property (strong, nonatomic) IBOutlet UIButton *uploadButton;
@property (strong, nonatomic) NSArray *arrayOfOurQuotes;
@property (strong, nonatomic) NSMutableArray *ourNumberOfQuotes;
Wyetro
  • 8,439
  • 9
  • 46
  • 64
Dinesh Sekar
  • 91
  • 1
  • 1
  • 8

3 Answers3

0

Are you switching to a different storyboard that your current viewController is already using? If it's the same, please change the code within your method (see below) - This line here UIStoryboard... isn't needed.

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];

isn't needed. You can call self.storyboard

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

   DetailViewController *detailVC = [self.storyboard instantiateViewControllerWithIdentifier:@"detailViewController"];
   detailVC.navigationItem.title = self.ourNumberOfQuotes[indexPath];
   detailVC.indexRow =  [NSString stringWithFormat:@"%@",indexPath];

   [self.navigationController pushViewController:detailVC animated:YES];
    }

Providing the detailVC has been set with the storyboard identifier @"detailViewController" of course.

Jim Tierney
  • 4,078
  • 3
  • 27
  • 48
0

Okay here is the problem, when I commented out your gesture codes from your viewDidLoad method, the delegate method, didSelectRowAtIndexPath gets called.

Here is what I figured, either the swipe gesture works and cell selection doesn't or if you remove the gesture part, the selection work and didSelectRowAtIndexPath gets called. As I never worked with gesture, I am not sure how to make both actions work together.

Hope this helps a little.

Natasha
  • 6,651
  • 3
  • 36
  • 58
  • the problem is that i cannot even go to the DetailViewCotroller. So what is the purpose of putting a breakpoint at the `-viewDidLoad` method when it doesn't even load – Dinesh Sekar Aug 24 '15 at 13:19
  • I gave you step by step debugging points. You would try to put breakpoint in DetailViewController if your code would have passed the first 2 steps. – Natasha Aug 24 '15 at 13:56
  • This is all correct here, you maybe forgot to include the reference in your .h – lukeswitz Aug 24 '15 at 14:03
  • I edited my response based on the updated question and looking into the sample code. – Natasha Aug 24 '15 at 14:41
0

From -didSelectRowAtIndexPath: not being called:

I have encountered two things in this situations.

You may have forgot to implement UITableViewDelegate protocol, or there's no delegation outlet between your class and your table view.

You might have a UIView inside your row that is a first responder and takes your clicks away. Say a UIButton or something similar.

You should check to make sure you have implemented the UITableViewDelegate protocol and you need to make sure that you are clicking the cell and not a view or gesture recognizer that is in front of it.

Community
  • 1
  • 1
Wyetro
  • 8,439
  • 9
  • 46
  • 64