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.
Related
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!
I have a block completion being called from within a button press message and, depending on state, optionally a UIAlertView being displayed. However, when invoked the UIAlertView appears three (3) times...
With the full information but it disappears itself and shows
Just the title shows and when I click OK
Appears again with full information (as in #1) for which I have to dismiss again
Following is a snippet of the code:
[credential performDataOperation:[credential commandForCreateOnClass:self.className]
withArguments:edits
completionBlock:^(BOOL succeded, id before, id after, NSDictionary *arguments, NSError *error) {
if (succeded) {
self.object = after;
self.objectWasCreated = YES;
[self prepareEditsDictionary];
self.navigationItem.rightBarButtonItem.enabled=NO;
}
else {
errorRecieved = YES;
[[[UIAlertView alloc] initWithTitle:#"Error" message:#"Error Message" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
}];
You are probably seeing just two alerts. The first appears, but you also have code somewhere that summons the second, so it overrides the first. Then you dismiss the second and the first returns. You need to hunt for your code that presents the second alert, the one without the message, and figure out why that code is running. Just do a global search in your project for UIAlertView! It must be in there somewhere, because all alert views are created and presented in code.
You may have accidentally hooked up your button so that it has multiple action handlers. Of course I could be wrong, but this is a mistake I've sometimes made, and then I've been mystified why my method was being called twice or some unwanted extra thing was happening when I tapped the button. Check your nib/storyboard or code to make sure. The fact that a single button can have many actions for a single UIControlEvent is very surprising and is almost never used intentionally.
(If that's not the right answer, then perhaps the solution lies in your performDataOperation method, whose code you do not show. Maybe it calls the simpler UIAlertView, in addition to calling the block.)
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.
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; };
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.