How to enter delete confirmation state UITableViewCell from custom action? - objective-c

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.

Related

Temporarily disable message handling by an instance - ios

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

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.

What's the order between pushing a view and viewWillAppear?

I made a viewController class which has a button, an input and a label.
What I want to implement is that when user click the button, a new view will be pushed and the input text will be showed in the label.
I used UINavigationController to memorize the text in input and set the logic in 'pushNext', which is the IBAction of the button, and the viewWillAppear method is used to put the text stored in UINavigationController into label.
I used NSLog to track the proc, and found that viewWillAppear always be called earlier than pushNext? But when I run the example code in my book, the called order was oppsite!
Why? Is there any attention to use these two methods?
The order should be
viewDidLoad
viewWillAppear
viewDidAppear

UITextView: Must I always resignFirstResponder?

Must I always resignFirstResponder for a UITextView? Or, will this happen automatically when its view controller disappears?
I'm asking because I'm having an issue similar to iPhone Objective-C: Keyboard won't hide with resignFirstResponder, sometimes, where the keyboard stays up even when the nav controller pushes and pops other view controllers. The keyboard works, and when I hit done, it unfocuses the UITextView (i.e., the cursor disappears), but the keyboard stays up.
I never found out why this is happening, but maybe it's due to not doing resignFirstResponder before pushing another view controller, but I thought it was optional?
At a total guess, the UITextView has a reference to the view controller (as its delegate) but does not retain it. When you go to the next screen, the controller is dealloced and then the UITextView (which has perhaps been retained by something else) tries to call back to the dealloced controller and crashes. When you call resignFirstResponder, you reverse the order this happens, and therefore no crash.
The way round this to add a textView.delegate = nil call in your view controller's dealloc method - obviously put it before you release the text view.
The contract between a UITextView and it's delegate says that the delegate will send -resignFirstResponder when the text view is done editing. This informs the framework that the view is done editing, fires the events relating to that (willEndEditing and didEndEditing), and allows other parts of the responder hierarchy to react accordingly. Failing to do so might work, but it's not following the contract (that's all a protocol is) it agreed to.
I don't think you have to because the Xcode Sample UICatalog UITextField doesn't call resignFirstResponder before the TextViewController is popped.
The reason the keyboard got stuck for me is that I was having the same view controller present two view controllers modally at the same time, one after the other. UIKit didn't like that.
Calling resignFirstResponder makes sure that the text property contains the actual text shown in the control.
Depending on the state this is not always necessary, but if your controls have resigned first responder, you know that you're working with valid data.

What Method to Override when View goes Active?

I have a Tab Bar Controller that contains five views. The views have elements that update a variable in the root app delegate. I'd like the views to change whenever this variable changes value.
In the absence of an event notification mechanism to update all views, I'd like them to update when they are displayed (ie., when their tab bar button is pressed.)
What method should I override? I thought it was viewDidLoad but I realize this is being called only once, and when I go to another view, make a change, and go back to it, nothing happens.
Try one of these
- (void)viewWillAppear:(BOOL)animated
- (void)viewDidAppear:(BOOL)animated
They will handle events just before and after a view of corresponding view controller will become visible.