Temporarily disable message handling by an instance - ios - objective-c

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 ....

Related

Detect which NSTableView is active

I have an NSSplitView showing two NSTableView instances. I need to detect which table view has become "active" (of focused), which means the one that the user has clicked. I need to know that because each table view acts as a source list for another view that shows the content of the selected row(s). This other view is shared for both tables.
I could do it by subclassing NSTableView and reacting to mouseDown: or another method but it I'd rather avoid subclassing just for that. I also don't want to track any NSWindow event just to know if the user has clicked one of the tables (I'd rather subclass NSTableView).
Currently, I use the delegate method tableViewSelectionDidChange:, but this method is, obviously, only called when the selected row changes. I need to know that a table becomes active even if the selected row hasn't changed.
Observing the clickedRow property of the table views doesn't appear to work. If may not be KVO compliant.
Any ideas?
For those interested, the most convenient solution I found was to take advantage of the fact that NSTableView is a subclass of NSControl. So just like NSButton it can send action messages when clicked (upon mouse up).
For each tableView, I wired its "action" to the same ibaction selector of my controller object in interface builder.
The controller identifies the sender and acts accordingly.
No need to subclass NSTableView.

IOS 7 Weather APP Like Transition/Animations

I would like to implement IOS Weather APP like transition, ListView, tap on list item it expands to detail view, or pinch to list also expands to detail view.
Slide left and right transitions. Please let me know how can I implement that.
Thanks in Advance.
Here is some post on a blog I found that explains Apple new Transitioning API on iOS 7, go through it, read it.
In short lines, here are the steps
1 - Set a transition delegate on a controller
There are 3 types of transitions you might want to customise :
UINavigationController push & pop transitions
UItabBarController tab changed transitions
any modal presentation with presentViewController:animated
Each of these 3 cases offers its own 'transition delegate' protocol :
UINavigationControllerDelegate
UITabBarControllerDelegate
UIViewControllerTransitioningDelegate
When, from somewhere in your code, you use the methods for presentation :
pushViewController:animated: or popViewControllerAnimated:
setViewControllers:animated:
presentViewController:animated
Then, these delegates asks for what I call an 'animator' if an animation is required.
What I'm calling an 'animator' is an object conforming to protocol <UIViewControllerAnimatedTransitioning> (or <UIViewControllerInteractiveTransitioning> in case of interactive transition, like gesture driven interactions). This decouples the animation from your UIViewControllers (which might already have plenty of code inside)
2 - Write the 'animator'
This is the object responsible for animating transition. This can be a viewController, or a completely new NSObject.
In case of a UINavigationController, you could define different animators for push and pop operation.
3 - add the properties you need for your animation into your animator, and code the animation
The 'animator' might implement different protocols, depending on which transition you're trying to customise.
In case of non interactive animations, these are the methods :
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext : define the duration of animation
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext this is where the beef goes. See the example code in link above,
- (void)animationEnded:(BOOL)transitionCompleted for any clean-up after your animation was played.
In your case, you might want to add some 'origin' and 'target' UIView properties in your animator class (as weak properties of course !)
Then, when you detect 'which' view was tapped by user. (in your UITableVIewDelegate or UICollectionViewDelegate didSelect methods), you tell your animator so that it can animate with THAT specific frame, then call the 'push', 'pop' or 'presentViewController' , depending on your navigation logic.
You can definitely pull this off with the transitioning api.
Check out this project, I think it will help:
https://github.com/chefnobody/Colors
I was able to do it using this example from Ash Furrow # Teehan + Lax: http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/ with some modifications:
To augment this example to get the pinch/pull table view cell separation animation you would need to identify the table view cell that was selected (or "selected" relative to the pinch gesture"), then in -animateTransition: you animate the actual table view cells above and below the selected cell out of view, revealing your details view controller. Remember, also to animate back to the table view from the details you need to (during the "pop") know which cell would be selected (scrolling it back into view if it's not already in view) then animate the cells surrounding it from off screen, back into view.
As for the swipe interaction between the different cities you would implement a different InteractionController that handles the transitions there. Again, you can probably follow Furrow's example and figure out how to pull it off.

Catching Button Events from Different ViewControllers

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.

How to enter delete confirmation state UITableViewCell from custom action?

I have a problem, I want to show right delete confirmation button of my UITableView's cell. Swipe to delete works just fine but I also want this to happen without swiping.
I would like to change cell's state from default to showing delete confirmation. There is bool property showingDeleteConfirmation but it's read only.
[self setEditing:YES animated:YES];
From custom cell's class doesn't do anything.
How to change cell's state to showing delete confirmation without swipe?
i.e. after swipe gesture on a cell is recognized what is being called? I would like to call it manually.
That is a delegate method meaning you should not call it yourself as that is a part of the process handles by the tableView class.
Instead you'll want to override the call class, prepare the method to show your button (or whatever you want to show) and animate other views trimming their frames. Doing that you'll understand the difference between the delegate and instance messages as you'll probably need to notify the tableView or it's delegate that your method is complete, the button is shown and other views are also animated.

How to initiate display of one view from another?

Assume you do not have a UIController to do the job. From inside the UIView .. how would you replace self with another UIView?
It's not very clear what you are trying to do from your question. UIController is not a class, for instance.
Ideally your app should be structured something like this:
UIViewController subclass
Controls a set of objects that are all on screen at one time. For example, any number of UITextFields, UIButtons, UIViews and UILabels.
has methods (IBActions and other delegate methods) which are triggered by user interaction with the controls and inputs.
has IBOutlets which allow it to manipulate what the user sees on screen. For instance an IBOutlet attached to a UILabel allows changing the text when a user presses a button.
UIView is only generally subclassed if you need custom drawing code, or some kind of custom control. Don't put application logic here if you can help it, and you can usually help it.
You can have multiple UIViewControllers but they usually function very independently. Often View Controllers don't maintain references for other view controllers. If they do it's loose couplings like the delegate pattern.
Bottom line: if you have two views controllers that need to communicate with each-other, you need to have a reference to one from the other. This usually occurs in the form of a property on one or both of the view controllers, and is connected either by interface builder or at run time when you create them.
You can add another subview using self.addSubview: you may also want to check self.bringSubviewToFront:
For more information, check the docs:
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html