I have a UINavigationController where the user can go back/fourth. When the user goes back, I want that UIView to reload. ( I am actually using an OHGridView ). On my ViewWillDisappear, I do something like this:
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] postNotificationName:#"ReloadOHGridView" object:self];
}
So when they go back, it will send a NSNotification to the OHGridView to refresh it's data. It get's called, but it get's an error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailViewController reloadData]: unrecognized selector sent to instance 0x4b9e9f0
Here's how I set up my NSNotificationCenter (in my DetailViewController):
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(ReloadGridNotification:) name:#"ReloadOHGridView" object:nil];
}
- (void)ReloadGridNotification:(NSNotification *)notification{
[database executeNonQuery:#"DELETE * FROM images"];
[items removeAllObjects];
[self reloadData];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Now you would think it would update, but I get that error... Please help!
Coulton
Actually, I wouldn't think that it would update. reloadData isn't the name of a documented method of UIViewController, and you don't seem to have implemented one yourself. I'm not familiar with OHGridView, but I perhaps that's the object to which you want to send the reloadData message.
So you can change the observer that you set up from self to your instance of OHGridView, or you can implement a method in your view controller called reloadData that in turn sends the appropriate reload message to your OHGridView.
Related
I am using custom MPMoviePlayerViewController.
Like below,
#import <MediaPlayer/MediaPlayer.h>
#interface customVideoViewController : MPMoviePlayerViewController
{
}
#end
I am calling this customVideoViewController class from other class to RUN my video serially in landscape mode, video is running fine but I am not able to catch the action onClick of DONE button of MPMoviePlayerViewController.
Can any one guide me.
this is how I am calling to this view.
customVideoPlayerObj = [[customVideoViewController alloc]initWithContentURL:self.url];
[self presentViewController:customVideoPlayerObj animated:YES completion:nil];
[customVideoPlayerObj.moviePlayer play];
I need to catch the action for DONE button click of this, how to do this...?
here is the observer for the same
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(doneButtonClick:)
name:MPMoviePlayerWillExitFullscreenNotification
object:customVideoPlayerObj];
but control is not coming in doneButtonClick
MPMoviePlayerWillExitFullscreenNotification and MPMoviePlayerDidExitFullscreenNotification fired when the movie player exits fullscreen.
You can use MPMoviePlayerPlaybackDidFinishNotification .
Can Anyone give a list of NWSWindow events sequence when NSWindow closes. More specifically which is the last notification that a NSWindow that closes sends. Apple docs are very sparse on any sequence stuff.
The messages sent to a window when closing are – windowShouldClose: and – windowWillClose:. These are sent to the window's delegate and conform to the NSWindowDelegate protocol.
Also you can register to receive NSWindow's notifications such as NSWindowWillCloseNotification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(windowWillCloseNotification:) name:NSWindowWillCloseNotification object:self.window];
- (void)windowWillCloseNotification:(NSNotification*)notification
{
// ... do something, save information...
NSWindow *window = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowWillCloseNotification object:window];
}
I'm trying to have a custom subclass of NSTableView observe the value of its own -selectedRowIndexes property, and I'm having trouble figuring out how to receive the notifications properly. My subclass looks like this (using ARC):
#implementation MyTableView
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
[self addObserver:self forKeyPath:#"selectedRowIndexes" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:NULL];
}
return self;
}
- (void)dealloc {
[self removeObserver:self forKeyPath:#"selectedRowIndexes"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
NSLog(#"change: %#", change);
}
#end
However, I never see -observeValueForKeyPath:... get called. Am I missing something?
I'm also open to a better solution - the reason I want to do KVO rather than relying on the delegate's -tableViewSelectionDidChange: method is that I'd like both the previous and current values for selectedRowIndexes, rather than just being able to get the current selection. If there's a way to do that without KVO on this property, I'm all ears.
If you're not seeing KVO notifications, I would open a radar at bugreport.apple.com. The reason is likely that they're not fully KVO compliant. I haven't tested, but I wouldn't be shocked.
As to how to do this without KVO, that's fairly straightforward. Use tableView:willSelectRowAtIndexPath: tableView:shouldSelectRow:. Check the current value, and the value to be added. Return YES.
I had the same problem, and I found the solution :
Bind the NSTableView view Selection Indexes to the array controller, key selectionIndexes
I have an UIAgent application with one window. I want to hide/show it from another application.How do I do it with cocoa? Seems like hide/unhide methods of NSRunningApplication doesn't affect UIAgent processes.
Thanks in advance
I solved it with NSDistributionNotifications. In the UIAgent application I add an observer to a #"QuitProcessNotification" (any other name):
[[NSDistributedNotificationCenter defaultCenter]
addObserver:self selector:#selector(quit:)
name:#"QuitProcessNotification"
object:#"com.MyCompany.MyApp"
suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
The callback looks like that:
- (void) quit:(NSNotification *) notification
{
[NSApp terminate:nil];
}
In the main application:
Sending notification:
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:#"QuitProcessNotification"
object:#"com.MyCompany.MyApp"
userInfo: nil /* no dictionary */
deliverImmediately: YES];
Be sure, that the object parameter is indeed your sender application's bundle identifier.
I've a class called AppController.h/m I want to make something when the NSNotificationDidResignActiveNotification is sent.
So i wrote this code in AppController.m:
-(void) initialize(){
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(applicationDidResignActive:)
name:NSApplicationDidResignActiveNotification
object:nil ];
}
and then
-(void) applicationDidResignActive (NSNotification*) note{
NSBeep();
}
The problem is that the method isn't executed and i get this in the Console:
+[AppController applicationDidResignActive:]: unrecognized selector sent to class 0x61c4
I can't get where the problem is: could you help me?
Thank you!
initialize is a class method, not an instance method. I don't know this for sure, but it seems that when using a selector in a class method, it also assumes that selector will be a class method (for good reason). AppController has an instance method called applicationDidResignActive, but not a class method named as such.
Instead of registering for notifications in +initialize, override -init and register there.
- (void)init
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(applicationDidResignActive:)
name:NSApplicationDidResignActiveNotification
object:nil ];
}