I need to figure out multiple UIActionsSheets? - ios

I am trying to create multiple UIActions sheets with my view. I have read a few questions on here and browsed the internet, but nothing seems to get me a valid answer.
I have tried the "switch and case" method that looks like this....
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
switch (actionSheet.tag) {
case 10:
if(buttonIndex == 0)
{
and I have tried this method too...
UIActionSheet *actionSheet1;
UIActionSheet *actionSheet2;
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex{
if(actionSheet==actionSheet1)
{
The action sheet options work as individuals, so I know that the links and code is right, but I can't seem to get them both to work at the same time.
Let me know if I need to post more code.
Cheers Jeff
More Info:
-(IBAction)Action01:(id)sender {
UIActionSheet *actionSheet1 = [[UIActionSheet alloc] initWithTitle:#"Please Choose a Website:" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Facebook",#"Twitter",#"Google Maps",nil];
actionSheet1.tag = 10;
[actionSheet1 showInView:self.view];
}
and the second one is set up with tag = 11.O have also linked the buttons in Interface Builder with the same tag number.
In my heads file, I have defined my properties and IB Actions as well. Everything is done properly as it works if i use only one or the other of the action sheets and comment the rest out.
Here are the links to the files if it makes them easier:
Header file
Implementation file
Cheers Jeff

You mention in your updated post that you have set the tags in Interface Builder and in code. This is likely causing a conflict. You don't want those IB buttons to have the same tags as the action sheet, or strange thing will happen.
Change the tags in Interface Builder and that should solve your problem.

Related

UIAlertView (or LMAlertView) with two stacked buttons

How can I create an UIAlertView with two stacked button? Instead of two buttons side by side? In my project I also use LMAlertView (GitHub repository) and I thought it would support them, but I can't find a way to obtain that very UIAlertView style.
Currently I create a UIAlertView with this code below:
LMAlertView *applicationUpdateAlert = [[LMAlertView alloc] initWithTitle:alertTitleFromServer
message:alertMessageFromServer
delegate:self
cancelButtonTitle:NC(#"Aggiorna ora")
otherButtonTitles:NC(#"Ricordamelo piĆ¹ tardi"), nil];
[applicationUpdateAlert show]
I don't know if this can be useful for you to better understand but LMAlertView has a property named buttonsShouldStack which I thought it would be useful for me but I can't properly use it, this is the code related to buttonsShouldStack in LMAlertView.m file (direct link):
- (void)setButtonsShouldStack:(BOOL)buttonsShouldStack
{
_buttonsShouldStack = buttonsShouldStack;
if (self.numberOfButtons == 2) {
[self.buttonTableView reloadData];
[self.otherTableView reloadData];
}
}
Thanks
Maybe you can give a try with this library. It has a demo project that cover your needs.
I fixed the problem by "rewriting" the LMAlertView component in order to treat UIAlertView buttons as UITableView's cells and by setting the rowNumber accordingly, if the alert has to show 1, 2 or more buttons. It's not an easy to show solution so I won't share the code here, also because I don't know if it's Apple's-approval safe.
Thanks to everyone!

How to create a flat UIActionSheet

Today's trend in apps includes flat designs, and now I am doing an app that follows with this trend. My problem now is how to create a UIAcionSheet that match with my App Screen's flat UI Design. In relation with this, I saw Instagram's action sheet and I found it interesting. I wish to have that design in my app. Anyone knows how to implement this in ios apps? I have provided a screen shot from instagram app.
You can use RDActionSheet from git
https://github.com/reddavis/RDActionSheet
I hope it will help you..!!
yes,
you can use https://github.com/reddavis/RDActionSheet and also u can change image and color of text and background image of action sheet
You can use FlatUIKIT from Git
https://github.com/Grouper/FlatUIKit
Go through the documentation & you will know how to use it. Awesome collection of Flat UI classes.
You can create a subclass CustomActionSheet derived UIActionSheet,
and create a method called CustomUI in it. Design your code here.
use CustomActionSheet like UIActionSheet, except must call method CustomUI of subclass in willPresentActionSheet delegate:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
if ([actionSheet isKindOfClass:[CustomActionSheet class]]) {
CustomActionSheet *sheet = (CustomActionSheet*)actionSheet;
[sheet CustomUI];
}
}

UIPageViewController - Verifying Page Turn with alert

I'm using a UIPageViewController to handle data entry where the last page is the active record and the previous pages are old records that can't be edited. So I need a way to verify that the user wants to leave the last page while allowing all of the other pages to navigate as usual.
Ideally I could really use a -(BOOL)pageShouldTurn method but that doesn't exist.
Does anyone know of a way to detect if a page is about to unload then stop the page turn based on some condition? I'm not having any luck with the gesture recognizer methods as they don't seem to be triggered even when the delegate is set.
Thanks to Michael, I've added this to my pageViewController which does exactly what I needed:
-(void)pageViewController:(UIPageViewController *)pvc willTransitionToViewControllers:(NSArray *)pendingViewControllers
{
if ([pvc.viewControllers.lastObject pageIndex] == [self.pageDataSource.allObjects count]) {
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:#"Are You Done?"
message:#"Once you leave this page you can't edit this record again"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alertDialog show];
}
}
So the alert box stops the page from turning only once. When it is dismissed, the user can then change the page. My version checks to make sure this only happens on the last page, you could remove the 'if' statement and alert on every page turn, but that would be annoying.
Seems to me there are at least two options.
Number one, you have "- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers". You might be able to catch a transition there and deny / force the old page to be reset.
Or, you can now subclass "UIPageViewController" and in your subclassed controller, you can define a new delegate protocol (incorporating all the original UIPageViewControllerDelegate" methods) and you can add your own "-(BOOL) pageShouldTurn" protocol method.
Both of these possibilities require iOS 6.

Is possible to declare something like lambda function what OK button from UIAlert is going to do?

In controller on different actions I need to show UIAlertView with "OK" and "CANCEL" buttons, and every "OK" click on those 5 UIAlertViews need to do different things. Is possible to declare something like lambda function to specify what "OK" button from each UIAlertView is going to do? (In code on 5 places I have with different questions and messages and actions on ok, some don't have text for input at all)
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Apply"
message:#"Are you sure you want to apply ?"
delegate:self
cancelButtonTitle:#"CANCEL"
otherButtonTitles:#"OK",
nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
(At the moment I remember action which cause UIAlertView to show and then based on action I do different things, but it is not clear code).
Use a category called UIKitCategoryAdditions that implements a block-based UIAlertView and UIActionSheet for the selection or cancel actions.
It makes it super simple to assign actions to many user prompts without having to implement the delegate methods and deal with handling more than one object's delegate response in the same controller.
It's possible, but by extending the existing controls. I would recommend using RIButtonItem, I'm using it myself in the latest couple of my projects.
Use an objective-c block in lieu of your delegate.
delegate: ^(UIAlertView * alertView, NSInteger buttonIndex) { doSomethingHere; };

How to show a table in an alert iOS

So I have a label, and when I click on it, I want it to show sort of a table in an "alert" type pop-up window that allows you to scroll (since there will be quite a few lines of data) through values like this:
1) some value : correct
2) Some other value : incorrect
The data I have is stored in two different NSMutableArrays.
I know I can make an alert show with some code like this,
UIAlertView *message = nil;
message = [[UIAlertView alloc] initWithTitle:#"Definition"
message:definition
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];
Is it possible to do this? If so, what should I look at?
Thanks
It will be a very bad solution - why not use modal controller instead?
Anyway, you can always add a subview to UIAlertView. However, note that changing its size could be complicated.

Resources