Undo button within a UIActionSheet - iphone

I have a UIActionsheet with several buttons setup. How would I go about adding a undo function? I'm using UITextfields

Set the appropriate UIActionSheet button to call the undo method on the desired UITextField's NSUndoManager object. For all UITextField and UITextView objects in iOS 3.0 and higher, there is an undoManager object that can be accessed and used to manage undoing and redoing of operations. The necessary code would go something like this:
(UIActionSheetDelegate method implementation)
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == /*undo index*/)
[yourTextField.undoManager undo];
}
EDIT: I suggest you look at the Apple documentation for Undo Managers, it should help you further with this should you need it.

Have you considered Shake to Undo? An Undo alert comes up if you enter some text in a UITextField/UITextView & shake your iPhone.

Related

Using my own UIAlertView around an existing library

I'm using a library called Chute to manage photo selection (from photo library, facebook, etc.).
I'm trying to implement a UIAlertView whenever selectionCount >= 20. The problem is, the Chute library handles alertView protocols in its own way, meaning some file is trying to execute
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{}
whenever my alert with buttons is displayed, which crashes the app. What should I do to work around the current method? I tried to subclass UIAlertView into a new custom class but I'm not sure where to implement the UIAlertViewDelegate or its protocol. Not sure if this is right either. Any help appreciated, thanks.
alertView: clickedButtonAtIndex: gets called on UIAlertView's delegate.

How to notify the alertview before showing to any view or window?

I am developing a application for iPhone.I have done some simple animation with start and stop buttons.I have a scenario to got any alert (ex: reminder) i need to stop the animation with out clicking stop button.
Can you please help me on this.
Implement the UIAlertViewDelegate protocol.
And implement the method - (void)willPresentAlertView:(UIAlertView *)alertView. There you can stop the animation. And you can continue the animation once the alertview is dismissed which can be detected by using - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex method.

Objective C Which Alert did the button press come from

another probably simple iPhone obj-c question for you...
I have a couple of alerts which have buttons in them that are presented to the user in certain circumstances, both are part of one view. Now I know how to tell which button was pressed, but how do I know which alert the button pressed is related to?
Any ideas would be really handy! Cheers!
Set a tag to each of the alerts, and compare the tag of the alert caught at the delegate method didDismissWithButtonIndex.
Set tag as, alert.tag = 10;
and check in delegate as
if (alertView.tag == 10)
Try to implement a simple delgate for your alert views.
For exemple using : alertView:clickedButtonAtIndex:
you will be able to know which alert view the button pressed is related to.
You can call UIAlertView's Delegate method explained below...and check for title or alert message like this.. here i had given you the example of title...
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0 && [alertView.title isEqualToString:#"Invalid"])
{
//Your Stuff goes here
}
}

UIALertView customization

I am developing an iPhone application, in which I want to use customized alert sheet. The customization is required since I want to set image for Alert-Sheet buttons, change the size of these button etc.
I have done the following things:
Created UIView with customized controls that I wanted.
Created and displayed UIAlertView
In the delegate method of UIAlertView (UIAlertViewDelegate) i.e
- (void)willPresentAlertView:(UIAlertView *)alertView
I am removing all the subviews of UIAlertView and adding my customized view as subview.
Everything works fine till here. Since I have used customized buttons, I need to remove the alert sheet explicitly in the Action Method of the button by calling dismissWithClickedButtonIndex:animated: on UIAlertView.
Even though the UIALertView gets dismissed, it takes around 0.5 second to get dismissed.
Can someone help me out to solve the problem of this delay in dismissing OR some other way of customization of Alert View buttons.
Thanks and Regards,
Deepa
I could get it worked by passing YES to dismissWithClickedButtonIndex:animated: call i.e [alertView dismissWithClickedButtonIndex: 0 animated: YES]. Initially I was passing the flag as NO. But, I don't know whey it takes less time if we pass the animation flag as YES.
Anyone knows this?
Instead of doing this
/*
1. Created UIView with customized controls that I wanted.
2. Created and displayed UIAlertView
3. In the delegate method of UIAlertView (UIAlertViewDelegate)
*/
do this:
Create a class like this:
#interface CustomAlertView : UIAlertView
{
//For ex:
UIButton *myCustomButton;
//and other custom controls
}
Implement it in following method:
-(id)init
{
}
In the above method use:
[self addSubView: myCustomButton];
I have given just the idea. I have code but not presently to share with you.
If you are not able to implement the above I will provide later.
Thanks.
Here is the library which can solve your UIAlertView Customisation issue. It can also work as UIActionSheet. It has very good customisation options.
https://github.com/Codigami/CFAlertViewController

How to get a notification for a UISearchBar hiding?

Is there any way to recieve a notification when a UISearchBar is finished (e.g Cancel button clicked or otherwise lost focus.
We don't have access to the UITextField inside, or I could attach an observer to it.
I can be notified when the keyboardWillHide, but I've got another text field, so it could be either one. And it becomes inactive before the keyboard hides, so no love.
I have access to the UISearchBarDelegate and UISearchDisplayController(Delegate).
Can anyone tell me where to look? Is there a master list of all notifications to choose from?
These methods should do it for you:
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar; // called when text ends editing
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar; // called when keyboard search button pressed
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar; // called when bookmark button pressed
- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar; // called when cancel button pressed
These are all UISearchBarDelegate delegate methods. By rule, delegate methods are more closely bound than adding observers for notifications. This was mentioned in one of Stanford University's iPhone videos. Though i myself use notifications generously and have found no problem with them.
In general, if there is not a Notifications section in the Apple docs for a class then there are no notifications that a publicly available for said class.
I would go with Chintan's suggestion of using the delegate.