开发者

didSelectRowAtIndexPath not called. UITableViewController subclassed

开发者 https://www.devze.com 2023-04-13 08:19 出处:网络
Tried programming more in an OO manner. NOTE: Seems the problem is related to having a UITableView(which is a type of scrollview) ontop of another UIScrollView. Trying to get clarification on how t

Tried programming more in an OO manner.

NOTE:

Seems the problem is related to having a UITableView(which is a type of scrollview) ontop of another UIScrollView. Trying to get clarification on how to make this work.

So i made a UITableViewController subclass and add that as an object in my Mainvi开发者_如何学运维ew class.

@interface NRTableVC : UITableViewController <UITableViewDelegate, UITableViewDataSource>
{
      NSArray * tableLabelsArray;
}
@end

The table scrolls and displays OK.

But my

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

method never gets called.

in my Mainview class I use it as follows

    RTable = [[[NRTableVC alloc] initWithStyle:UITableViewStylePlain]autorelease];
[scrollview addSubview:RTable.view];

I was wondering so I need to somehow set self as the delegate or something like that.

Anybody able to give me some hints as to what is wrong?

Many Thanks, Code


Have you set delegate for tableview? Without delegate set it won't call any delegate methods.


What I usually do is, in the View I want the tableview is create an instance

I do this in ViewDidLoad or the LoadView methods

UITableView *tableView = [UITableView alloc] init...
tableView.delegate = self;
tableView.datasource = self;

Then I add it as a subview of the current view.

This means your MainView needs to implement the tableView datasource and delegate methods.

Edit:

If you use interface builder, remember to drag the datasource and delegates to the fileowner


Is anything retaining RTable? You're autoreleasing it but you don't show any code that indicates it's being retained anywhere.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号