In a Single-View iOS app I’m currently working on, I have a view controller designed to manage playback of an audio stream, as well as a series of UI elements for playback control, scrolling, etc…For the sake of clarity, we’ll call it AudioStreamerViewController.
A ‘track selection’ button in this view is wired to an action displays a TrackSelectionTableViewController modally, with the intention of allowing the user to select a track and return to the playback view when tableView:didSelectRowAtIndexPath: gets called.
When this row selected method fires, the objective is to message the delegate callback method in AudioStreamerViewController that then attempts to execute self.currentTrack = trackObjPassedToCallback.
The problem is AudioStreamerViewController calls its currentTrack setter a seemingly infinite number of times (like an “I have to stop the simulator or I’ll run out of memory” number of times), and I cannot seem to figure out why. I took a screenshot of the call stack. It had a breakpoint set so it only shows seven calls in the image, but believe me, it’ll keep going =)
I’m wiring the two ViewControllers up by making AudioStreamerViewController the TrackSelectionTableViewController‘s delegate using the following prototype:
// in TrackSelectionTableViewController.h
@interface TrackSelectionTableViewController : UITableViewController {
NSMutableArray *tracks;
}
@property (nonatomic, assign) id<TrackSelectionTableViewControllerDelegate> delegate;
@protocol
// in TrackSelectionTableViewController.m
@synthesize delegate;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Track *trackSelected = [tracks objectAtIndex:[indexPath row]];
[self.delegate userDidSelectTrackFromTableView:trackSelected ];
[self dismissModalViewControllerAnimated:YES];
}
AudioStreamerViewController‘s prototype and delegate callback look like:
// in AudioStreamerViewController.h
@interface AudioStreamerViewController : UIViewController <SCDJTrackSelectionViewControllerDelegate> {
Track *currentTrack;
}
@property (nonatomic) Track *currentTrack;
-(void)userDidSelectTrackFromTableView:(id)trackObj;
// in AudioStreamerViewController.m
@synthesize currentTrack;
-(void)userDidSelectTrackFromTableView:(id)trackObj
{
self.currentTrack = (Track *)trackObj;
// other handling code...
}
I’ve tried to do this a number of ways, and each of them produce the same end result. Can anyone identify any indicators of why this is happening? Also, is there a more attractive / stable approach to implementing this idea? If so, what are the benefits?
The answer is in your stack trace.
-setCurrentTrack:is calling-setCurrentTrack:. What is your code for-setCurrentTrack:?