3

I have a UITableView inside a UIViewController like so:

.h

@interface OutageListViewController : UIViewController<UITableViewDelegate,UITableViewDataSource> {
   IBOutlet UITableView *outageTable;

.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   NSLog(@"Selected");
}

I have customized table cell:

//EDIT I have fire UILabel side by side on my customized view, as well as a background spreading the entire area. But after resizing/removing the background image and label I putted on the customized cell, "didSelectRowAtIndexPath" is still not being called. //END EDIT

@interface AbstractSummaryListViewCell : UITableViewCell {...}

and

@interface FiveColumnSummaryCell : AbstractSummaryListViewCell {...}

This UIView is inside another UIView:

@interface CustomTabBarController : UIViewController {
   OutageListViewController *outageListViewController;

And my AppDelegate add this to the window:

[window addSubview:[customTabBarController view]];

Now I'm trying to determine which cell get clicked and didSelectRowAtIndexPath doesn't get called, I have dataSource and delegate connect from the UITableView to File's Owner, in fact the data populates correctly as my "cellForRowAtIndexPath" specifies, any ideas how can I fix this?

Thanks!

Derek Li
  • 3,089
  • 2
  • 25
  • 38
  • When you touch the cell, does it turn blue for a second? – Alex Gosselin Aug 02 '11 at 00:18
  • Alex, sorry for missing this information from my original post. No, it doesn't turn blue when I touch it. I can scroll up and down and data is showing correctly though. – Derek Li Aug 02 '11 at 04:09
  • Try removing one of the subviews so there's a "hole" and tap the cell there, let us know what happens, we need to narrow down the problem in order to fix it. – Alex Gosselin Aug 02 '11 at 10:56
  • possible duplicate of [-didSelectRowAtIndexPath: not being called](http://stackoverflow.com/questions/255927/didselectrowatindexpath-not-being-called) – Leena Sep 10 '14 at 08:51

4 Answers4

4

I solved it: forgot to check User Interaction Enabled in my customized cell xib. What a fool!

Derek Li
  • 3,089
  • 2
  • 25
  • 38
3

Are the following properties of UITableView all YES?

  • allowsSelection
  • allowsSelectionDuringEditing

Edit: I think Paul is right. The delegate property has some problem. You can check the delegate property of tableView inside -(void)viewDidLoad. As you said, they should be connected to FileOwner in xib. So the following codes won't obtain nil.

- (void)viewDidLoad {
   [super viewDidLoad];

   // They should not be nil.
   NSLog(@"delegate:%@ dataSource:%@", self.tableView.delegate, self.tableView.dataSource);
}
AechoLiu
  • 17,522
  • 9
  • 100
  • 118
  • allowSelection is default to YES and allows SelectionDurningEditing is default to NO, since I don't need editing feature, I kept them that way. Even with a outageTable.allowSelection = YES, I still don't see the cell turns blue when I touch it. – Derek Li Aug 02 '11 at 04:13
  • I has edited my answer, you might need to check the properties about tableView. – AechoLiu Aug 02 '11 at 08:25
  • I added the NSLog to my `OutageListViewController`'s `viewDidLoad` and I got **delegate: dataSource:** as input. However I have to do `outageTable.delegate` and `outageTable.dataSource`, if I add `self`, there's an error telling me **Property 'outageTable' not found on object of type 'OutageListViewController *'**, any ideas? (In .h, I have `IBOutlet UITableView *outageTable`, but I don't have `@property` and `@synthesize` for it.) – Derek Li Aug 02 '11 at 08:46
  • Well, is the 0x5a8f620 the same as `self`, which is responsible for the method `-(void)tableView:didSelectRowAtIndexPath:` ? The original problem seems like that method doesn't fire. As for me, I will add `@property` and `@synthesize` for it. I remember an Apple official document suggests add them under iOS. – AechoLiu Aug 02 '11 at 11:27
  • Maybe you can find something useful in this `Table View Programming Guire`, which provides some sample codes about table view. http://goo.gl/2xvnO. – AechoLiu Aug 02 '11 at 11:32
  • I nslog `self` and it's **** as well, so I think the connection from UITableView to File's owner should be fine, right? – Derek Li Aug 02 '11 at 16:33
2

It's possible that the view controller has not been connected to the delegate property of the outageTable anywhere.

Paul Blessing
  • 3,815
  • 2
  • 24
  • 25
  • `outageTable`'s `delegate` is connect to File's Owner, which is a `UIViewController`, is that what you're referring to? Thanks. – Derek Li Aug 02 '11 at 04:15
  • @Derek Yes, that's what I meant. – Paul Blessing Aug 02 '11 at 13:29
  • So I verified the connection in IB, as well as the NSLog method TORO mentioned below, and it seems the connection is working fine, any ideas what the problem might be? Thanks. – Derek Li Aug 02 '11 at 16:35
0

You can make a quick test... Remove the "big" label and see if the didSelectRowAtIndexPath is called.

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • I tested this right after I post the question, no after removing the background image and label I putted on the customized cell, "didSelectRowAtIndexPath" is still not being called. – Derek Li Aug 02 '11 at 00:17