I have a scroll view, inside a collection view cell. The scroll view has a class of its own (ClassA), as does the collection view (ClassB). When you tap the index row, it expands. Sweet, works just fine. Only problem is, you have to tap on the index row to collapse the cell. Since there is a UIScrollView hanging out in the cell, tapping on it won't collapse the cell. So, what I did was create tap detection in the scroll view. The tap detections selector then handles collapsing the cell via notifications:
Class A:
- (void)singleTap:(UITapGestureRecognizer *)gesture {
// Post a notification to collapse
[[NSNotificationCenter defaultCenter] postNotificationName:#"collapseCell" object:nil];
}
Class B:
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(deselectItemAtIndexPath:animated:)
name:#"collapseCell" object:nil];
}
Error: 'NSInvalidArgumentException', reason: '-[CollectionViewController deselectItemAtIndexPath:animated:]: unrecognized selector sent to instance 0x7caa
That NSNotificationis not doing what you think it's doing. Its not calling or trying to call the UICollectionView's delegate method, deselectItemAtIndexPath:animated:. Its actually looking for a different method, but with the same signature as the UICollectionViews delegate method.
Make a test method, call it something simple and see if that works to confirm what I think is happening.
Related
I need to find the way to respond to notification centre being closed/hidden. The reason is that I have a pop up NSMenu in that widget, and if you open it and then close entire notification centre, pop up menu remains on the screen.
I have already tried to implement NSWindowDelegate but there is no such event that defines closing of today widget centre. The closest things I found are -windowDidMiniaturize: and
-windowWillClose:. But when side bar closes they are not invoked.
Finally I have found needed method in NSWindowDelegate protocol.
First step is to add self (in that case it is viewController) as an observer for desired method: windowDidResignKey:
-(void)viewWillAppear {
//set this view controller delegate for selector windowDidResignKey
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:self.view.window];
}
And second is to implement this method:
- (void)windowDidResignKey:(NSNotification *)notification {
//If window did resign key (close today center) - close menus
if(_sourceLanguageMenu)
[ _sourceLanguageMenu cancelTracking];
if(_targetLanguageMenu)
[ _targetLanguageMenu cancelTracking];
}
In my application, I have a NSWindow that has a NSTableView object and a few buttons. When the user presses the "new" button, an "ItemAdd" NSWindowController is activated where the user types in attributes for the item to be added to the NSTableView.
My question is this: since NSTableView requires reloadDatato update its view, how do I call reloadData after the ItemAdd window closes and focus shifts back to the NSWindow with the NSTableView.
Thanks for the help!
You could put reload data in a notification handler:
Put this in an initialization method of an object that you want the notification to get called on:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didBecomeMainWindow) name:#"NSWindowDidBecomeKeyNotification" object:nil];
Then make a method something like this:
- (void) didBecomeMainWindow
{
[tableView reloadData];
}
You can subclass the NSWindow and override the following method:
- (void)becomeKeyWindow
I have a UIPopoverController named popover in another view. What I would like to know is, how can I dismiss the popover if a UIButton was pressed in the current popover view? Thanks in advance.
I always found it odd that a UIViewController knows how big it should be in a popover through it's "contentSizeForViewInPopover" property, but doesn't keep a pointer to the UIPopoverController itself. I always end up adding:
#property (nonatomic,assign) UIPopoverController* popover;
to my UIViewController classes, and set that when creating the popover. Then from anything in that UIViewController, I can do this to dismiss the popover:
[popover dismissPopoverAnimated:YES];
You could use an NSNotification to tell the other view to dismiss it's popover view.
Example usage:
// Add an observer that will respond to our notification.
[[NSNotificationCenter defaultCenter] addObserver:self // <- This is the object that will has the selector that we want to run (the same one we use in the next line).
selector:#selector(doSomething:) // <- This is the selector we want to run.
name:#"doSomethingNow" // <- This is notification name we will send to activate our observer's selector.
object:nil]; // Don't worry about this for now.
// Post the notification. This has the same name as our observer above, so our 'doSomething' selector should be run.
[[NSNotificationCenter defaultCenter] postNotificationName:#"doSomethingNow" object:nil];
// the function specified in the same class where we defined the addObserver
- (void)doSomething:(NSNotification *)pNotification {
NSLog(#"Received Notification...");
}
Im my application, I display a NSView when a user click on an icon in the systemstatusbar.
This NSView is displayed with MAAttachedWindow.
My question is : how to refresh the NSView content when the attachedWindow is displayed (makeKeyandorderFront)
I've tried to refresh the content in the awakeFromNib method,but it works only once.
Could anyone help me?
thanks
The solution I've found:
I've added a observer in my view:
I've set the object to [selft window] to listen the NSWindowDidBecomeKeyNotification notification of the MAAttachedwindow.
-(void)awakeFromNib
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:[self window]];
}
-(void) windowDidBecomeKey:(NSNotification *)note
{
// Do refresh here
}
The reason -awakeFromNib only works once is presumably because you're only loading the assembly from the xib once and keeping it around.
Presumably whatever action actually shows your view in the MAAttachedWindow instance is the ideal place to "refresh" it before display, ie your own call to -makeKeyAndOrderFront:.
So: What have you tried?
My navigation Controller 's Root viewController is UIViewController(rootViewController).
It contain's a UITableView, as follows:
alt text http://www.freeimagehosting.net/uploads/c9b0985b63.png
When i press the arrow button(call the function in rootViewController), the tableview will move to left until only the arrow button left on the left edge.
But now i also want to press the cell to make the same function. But the problem is the method didSelectRowAtIndexPath: cant call that function in rootViewController. So how should make this ?
I guess use addObserver method, but know nothing about this , anyone can explain or give me some idea , thanks a lot!
Two ways:
1.Make the "Map" view controller is the delegate of navigation view controller. Then in
didSelectRowAtIndexPath:
call the [delegate buttonPressed];
2. When the button was pressed first time, add a observer:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(buttonPressed:) name:#"flip_the_navigation_controller" object:nil];
Then when the cell was pressed, post a notificatoin:
[[NSNotificationCenter defaultCenter] postNotificationName:#"flip_the_navigation_controller" object:nil];
And remove the observer in dealloc method:
[[NSNotificationCenter defaultCenter] removeObserver:self];