I'm trying to set datasource for my table view programmatically, I have a class which I created and it implements (I don't know if implements is the right word for it, new to OC, I come from Java) the UITableViewDataSource protocol.
@interface PlaylistController : NSObject <UITableViewDataSource, UITableViewDelegate>
in my ViewController in the viewDidLoad method I try to assign the datasource, but I get EXC_BAD_ACCESS.
[playlistView setDataSource:[[PlaylistController alloc] initWithPlaylist:playlist]];
And I don't know why?
From reading here (SO) I understand that it either a casting problem (but I do implement the needed protocol), or memory management problem (but I'm using ARC, not touching release at all)
Instead of
[playlistView setDataSource:[[PlaylistController alloc] initWithPlaylist:playlist]];
Use
[playlistView setDataSource:self];
Reason:
You tried to set DataSource to an instance that is in autorelease. It gets released and you get the Error.
You should set the dataSource to self, so that it points to the current instance of the class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With