user1673099
user1673099

Reputation: 3289

Dismiss Modal view on Popover row selected in iphone SDK

I present a modal view on a button Tapped.

In that view, I made a new view(extra view). In Extra view, i have a UITableView & a UIButton.

When i click on that button,i open a view (Leftview) in popOVer.Now, i want to dismiss the "Extraview" on click of leftView's Table row.

MY code is as follow:

// Leftside view:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    [[NSNotificationCenter defaultCenter] postNotificationName:@"DismissModal"object:nil];

}

// Presented modal view.m


- (void)viewDidLoad
{

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissModal:) name:@"DismissModal" object:nil];
}


-(void)dismissModal:(NSNotification *)notif
{

   [self dismissViewControllerAnimated:YES completion:nil];

}

My error is as follow:

[Reader_View dismissModal]: unrecognized selector sent to instance 0xb494e10 2013-01-08 16:12:00.468 AFFeedsReader[3449:1d903] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Reader_View dismissModal]: unrecognized selector sent to instance 0xb494e10

Upvotes: 0

Views: 387

Answers (3)

Mohammed Shahid
Mohammed Shahid

Reputation: 175

Please Do not use Notifications for Simple tasks as it consumes much resources ...so kindly go with any delegate method available always..unless there is a real need of getting notifications on the whole of the app..

Upvotes: 0

user1673099
user1673099

Reputation: 3289

i solved this by implementing post notification.

Upvotes: 0

MuhammadBassio
MuhammadBassio

Reputation: 1570

In your "Leftview.h", do the below

@protocol DismissingDelegate

- (void) dismissextra;

@end
@property (weak, nonatomic) id<DismissingDelegate>delegate;

When initializing your leftview, assign the delegate to the ViewController that shows the modal one.

In that controller, define it as a "DismissingDelegate", and implement the below method:

- (void) dismissextra {
     [self dismissModalViewControllerAnimated:YES];
}

Upvotes: 1

Related Questions