开发者

Using UITableView without a Controller - getting unrecognized selector error

I'm not sure if I'm going about this right. All the tutorials I've seen suggest that nearly all the controls, which are views, are handled by their own ViewController. But the Apple docs clearly state that it should be one ViewController per screen, and I have more than one thing going on per screen. If I'm supposed to hav开发者_如何转开发e multiple ViewControllers per screen, how do I hook that up in IB?

I've put a UITableView onto my main view, and then I created a custom class to handle it. I implemented the UITableViewDataSource and UITableViewDelegate protocols necessary, and then I added it as an object into my XIB file. I hooked up the table to that object, and I made sure to set the class of the object to the one I created.

The problem is, simply having a willSelectRowAtIndexPath method defined in my custom class causes the app to crash when I click a table row, with an "unrecognized selector" error. I've gone through dozens of forums and such looking for the answer, but they're all about making sure the class is set right (mine is) or something about leaking memory (for people who didn't use IB to create it.) So I'm totally at a loss now for why this is happening. Is it because my custom class isn't a subclass of UIViewController?

edit: I fixed the actual issue by moving the code into my main UIViewController, and setting the table's datasource and delegate to that (the File's Owner) and it works. But I'm still very confused on why it refused to work before. All the links and properties seem to have been set up just fine.


did you set your custom class to be a UITableViewDelegate?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜