Reputation: 4126
I've a viewController
called AudioViewController
. In that, I've this method:
- (IBAction)stopAction:(id)sender
{
[self.audioClass stop];
}
I've a NSObject
class called AudioClass
. In that, I've these methods:
-(void) stop
{
if (!recorder.recording)
{
[player stop];
player.currentTime = 0;
[self.recordOrPauseButton setEnabled:YES];
[self.stopButton setEnabled:NO];
[self alertMessage];
}
else
{
[recorder stop];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:NO error:nil];
[self alertMessage];
}
}
-(void) alertMessage
{
UIAlertView *stopAlert = [[UIAlertView alloc] initWithTitle: @"Done!"
message: @"Do you want to save it?"
delegate: self
cancelButtonTitle:@"Cancle"
otherButtonTitles:@"Save", nil];
[stopAlert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger) buttonIndex
{
if (buttonIndex == 0)
{
// this is the cancel button
}
else
{
[self.sqLiteDB insertDataIntoTable:soundFilePath And:outputFileURL];
[self.navigationController popViewControllerAnimated:YES];
}
}
Now, here in
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger) buttonIndex
it is not recognizing the
[self.navigationController popViewControllerAnimated:YES];
.
Because, It is in the NSObject
class. How can I access that navigationController
and return from AudioViewControlelr
to it's previous ViewController
?
If any one have any solution, please share it with me. Thanks a lot in advance. Have a good day.
Upvotes: 0
Views: 109
Reputation: 13296
iOS development is based on the Model View Contorller design pattern. Your AudioViewControlelr
is obviously a controller and your AudioClass
would actually be a model. In MVC, models should never directly modify views, this includes modifying UINavigationControllers
and displaying UIAlertViews
.
In your case, your AudioViewController
should call stop on the AudioClass
object and show the UIAlertView
.
On a side note, AudioRecorder
would be a better name than AudioClass
. It more accurately describes what the class does, as opposed to just telling us it's a class which we already know.
Upvotes: 1