views:

47

answers:

1

I have setup a sample application using a UITableView. Initially I did this by conforming my controller to <UITableViewDelegate> and <UITableViewDataSource>, added a tableView in IB and connected "datasource" & "delegate" to Files Owner. It all works so thats good.

What I have been trying out is creating my own class for the delegate. I created a new class and added <UITableViewDelegate> and <UITableViewDataSource>, but quickly found I could not connect the tableView>dataSource / delegate. To solve this I added an "Object" (NSObject) in IB and set it to my new class. I then connected the dataSource and delegate outlets to this object. It sort of works, the app runs and displays the tableView, but when I try and scroll the table the app crashes. Can I ask if I am going about this the right way?

gary

+1  A: 

You are doing exactly the right thing to get an instance of your class into the nib file. I use that method all the time for NSTableView data sources. Your problem is possibly that you are not initialising data source / delegate ivars correctly for an object that is in a nib. For instance, if you have an NSArray being alloc'd in some init method, the init method might not be getting invoked. You need to post some code really to confirm this.

Anyway, try creating a method called awakeFromNib in your new class and putting the initialisation in that.

JeremyP