I successfully added custom UIMenuItems to the context menu of a UICollectionViewCell.
When using the builtin actions (cut / copy / paste) the -collectionView:performAction:forItemAtIndexPath:withSender delegate method gets called.
But it never gets called if invoking custom actions. Is there any easy possibility to get the corresponding UICollectionViewCell from the UIMenuItem?
Here is an example, take a look at this http://paulsolt.com/2012/11/uicollectionview-custom-actions-and-uimenucontroller/
Related
I need to show a sheet dialog soon after the main window has been shown after first run. If I do it in the init or awake from nib , it does not seem to work right (sheet show as window detached from main window if I do it in the init method). I guess I have to show sheet once the parent window has shown. I have an appcontroller class which has a window pointer. So I guess I need to register as a delegate or something with window ? and implement some method to receive that call ?
Thanks,
There is no reliable event, notification, or delegate method call. It is expected that your code is responsible for showing the window, so it should already know when the window is shown.
Are you relying on the Visible at Launch property set in Interface Builder? If so, what you using to load the NIB? Hopefully, a window controller. In that case, you should be calling the -window method to load the NIB and obtain the window. The resulting window reference is what you would pass to the method that begins the sheet.
If not relying on Visible at Launch, what code are you using to show the window? For example, invoking -showWindow: on the window controller? So, put the code to show the sheet right after that.
applicationDidFinishLaunching: is your entry point. It is sent to your app delegate after the app is all set up, but before the user has had a chance to interact with it.
I have a class inheriting the UICollectionViewCell. In this class I implemented touchesBegan and touchesMoved selectors. This allowed me to implement dragging of the cells.
Later I decided to use the same cells implementation in another view hosting another CollectionView. The behavior of the cells are exactly the same but the touches handling should be disabled since I want to allow the didSelectItemAtIndexPath of the CollectionView delegate to be called when the user taps a cell in this view ( instead of the custom dragging as in the previous view ).
Having if inside the touchesBegan/Moved functions is not an option since the fact that those methods are present "steals" the messages and they no longer trigger the selection inside the UICollectionView ....
I tried to forward the messages to the view but it is a mess ...
What I am looking for is to somehow dinamically set that my instances of the cell do not react to the "touchesBegan/Moved" messages
I saw this but it is not exactly the same ....
Background:
I have a UICollectionViewController that shows items in one of two modes, which the user can toggle between. Each mode uses a different class of UICollectionViewCell. Let's call these modes "list view" and "grid view".
When I switch modes, I call .reloadData on the UICollectionView, which redraws the collection view using the correct cell classes. Everything works fine here.
Now: Inside the UICollectionViewCell subclass for one type of cells, I want to be notified when the collection view that contains it switches modes. Visually, a cell which was on-screen vanishes; the collection view is drawn fully with the other type of cell. When switching back, the cell is re-displayed.
Question:
How can I be notified when a UICollectionViewCell is "removed" (i.e., no longer shown; I'm not sure what's happening under the hood yet) from its parent collection view?
Notes:
prepareForReuse is not called on the cell when the collection view's updateData causes the cell to no longer be included.
willTransitionFromLayout:toLayout: (an empty layout?) is not called.
Overriding didMoveToSuperview is of no help; it is not called.
Observing .hidden or .alpha on the cell does not work.
The cell's dealloc is not called; it sticks around in the reuse queue.
Something in the cell must be changing that I can observe or hook into, what is it?
Update: UICollectionViewDelegate has this method, which from the documentation seems like it does what I am asking:
collectionView:didEndDisplayingCell:forItemAtIndexPath:
Original answer:
I got this working as desired by having the UICollectionViewController manually notify visible cells of impending doom with this method when I'm about to toggle and call reloadData:
- (void)notifyCellsWillBeHidden {
for (UICollectionViewCell *cell in self.collectionView.visibleCells) {
if ([cell respondsToSelector:#selector(willBeRemovedFromCollectionView)]) {
[cell performSelector:#selector(willBeRemovedFromCollectionView)];
}
}
}
These cells can then do what they need to do if they implement the above method.
Calling prepareForReuse may not a good idea because it will be called again before the cells are re-displayed, if this is a problem.
I'm still curious whether there is a way for a cell to receive notification that it is going to be made non-visible without an explicit call.
My Setup
I have a ViewController, where users type some sort of text in there. Call it InputViewController.
I have a UIView (in a separate class), where I draw a navigation bar that has a gradient (I override drawRect for Core Graphics, hence I need to to have in a separate class) which has a button. The button takes you to a MapViewController, which allows you to add a location tag to your input. Once a location tag is added, I would like to change the button's image.
My Problem
Once the button is tapped, I need to send the user's input to the MapViewController, where a delegate is also implemented and will pass back some information back to the InputViewController. The issue here is that the button resides in the separate UIView. One way to do this is pass the UIView the information once they are set, which in turn would be passed to the MapViewController once the button is tapped. The problem here would be the delegate as the delegate needs to return to the InputViewController and not the `UIView.
I was wondering if its possible to move the UIView into the InputViewController, including the drawRect method for that view. If so, how can I do that? If not, what are other ways/suggestions I can do to have the above set up?
I guess you need to use NSNotifications for sending messages to your classes. See this.
Hi I have a quiz app that I am working on, and on my RootViewController I have two buttons with action methods, now when I press on one of the buttons I get my questionViewController and text is loaded into specific fields, I do this by using the viewDidLoad method. When I go back to the RootViewController and click on a different button I want to show the same questionViewController but with different text, how can I go about doing this?
I just finished a project with similar requirement. One way to do this is to use static variable and class method in your questionViewController class.
You could implement viewDidAppear: on your questionViewController, and set the text there instead of viewDidLoad.
You could also implement a method on questionViewController, that updated the text fields, and call this method from the RootViewController.