I've seen a number of blogs claim that UIAlertView from firmware 3.0 onwards will show a table view if too many buttons are added to it to fit in the alert box. However, I don't seem to find this the case, either in the simulator or on the device. Before I look at using one of the mechanisms for manually adding a tableview to an alert, I want to make sure I'm not replicating something the OS already does.
No, the thing that shows a table view is UIActionSheet when it has too many items. It's really ugly.
I've never heard of this behavior until you asked, and I've never observed it. Reading the entire UIAlertView documentation leads me to believe that this is not the case.
It sounds like you already tried adding a bunch of buttons to the UIAlertView and weren't able to replicate the behavior, so I'd call this one busted.
Yes, if you add too many buttons into UIAlertView, it will show them as tableView.
More than that, any amount of buttons you see in UIAlertView are part of integrated UITableView. So any time you click the button in the alert, you actually call didSelectRowAtIndexPath: of UITableView.
Related
I want to add more than 8 buttons in UIAlertView but when I am adding buttons, they are covering each other and not scrolling. The title is also hiding.
How can I resolve this and add some scrolling in the alertview ??
Seems like this kind of question comes up at least once a day on StackOverflow, but if you want to mess around with the various components within a UIAlertView, the short answer is: DON'T.
If you look at Apple's documentation for UIAlertView, within the first screenful of text it states:
Subclassing Notes
The UIAlertView class is intended to be used as-is and does not
support subclassing. The view hierarchy for this class is private and
must not be modified.
This means that there's a decent chance that any mucking around within UIAlertView hierarchy could catastrophically break your app in future iOS release.
So if you want to add scroll bars or bells & whistles, you really should create your own custom UIView (which looks like a UIAlertView, but is wholly of your own creation)
If you have more buttons then UIActionSheet is the best option than using UIAlertView. If you dont want to use UIActionSheet there is always a custom View to your rescue!
You should really rethink your UI if you need more that 8 button in a UIAlertView. 8 button is the maximum the standard alert view can handle.
Either build your own alert view or use a normal view controller with a table view.
Not sure if it's necessary but as an alternative, you can present another ViewController/ModalVC that will have all the attributes that you may require....
Just move ahead with CustomView, Otherwise not possible with UIAlertView to meet up with your requirement :
Reference links :
http://iphonedevelopment.blogspot.in/2010/05/custom-alert-views.html
http://iosdevtricks.blogspot.in/2013/04/creating-custom-alert-view-for-iphone.html
https://stackoverflow.com/a/6965828/434898
If you want to add many buttons you can use a custom implementation for the alertView.
A nice example is FUIAlertView
Or you could use WEpopover and add to it a table view.
I am implementing something like Eula in my iPhone app. I need to enable the confirm button only when user reads whole Eula (scrolls along whole long text).
I am using UIAlertView, with long inside text. Thanks to this, the text field inside alert view have a scroll bar on its right side.
I need to access the delegate of this scroll, because I need to enable OK button only if user scrolls down with scrollable text.
If you are planning to release this app on the AppStore, you can't do it using the builtin UIAlertView.
UIAlertView doesn't have any method, and it's delegate protocol doesn't give you this kind of information.
Probably you can achieve this iterating through the subviews of the UIAlertView instance, but doing this will guarantee your app the rejection :-)
the only thing you can do is to create your own "MYAlertView" component
I have an iPhone application which is, in essence, a list. There is a UINavigationBar at the top, and then there is a UITableView which holds the list. I'd like to have an option in some way or another of allowing the user to sort the list in different ways. So, in my mind, I picture having a NavigationItem on the UINavigationBar that, when touched, a little pop up dialogue comes up. You select the "sort" you want, a check mark appears next to it, and the dialogue goes away.
I'm not really sure how to do this. I tried creating a UIView, adding a UIViewController onto it (which held this list of different "sort" parameters (ex. sort alphabetically, sort by date, etc) in a UITableView. But the UITableView isn't responding to any touches, and I'm not sure why.
Does anyone have an idea for using Apples wonderful interface for having an option like this? I can't use a UISegmentedControl below the UINavigationBar, because there are 5 possible options, and I can't fit all that in a single UISegmentedControl.
This sounds like a job for the UIPickerView. You could just slide one up from the bottom of the view whenever that button is pressed. I've done this in the past and it works well.
You won't get a checkmark, but if you want a pop-up I suggest using a UIAlertView.
Have you looked into UIActionSheet at all? https://developer.apple.com/documentation/uikit/uiactionsheet
It seems like it might be a good fit for this approach. The action sheet will be a bit tall since you will have 5-6 buttons in it, but it should get the job done and they are really easy to implement.
The way you are approaching it with displaying another view with its own UITableView in it would work also, but it doesn't seem like the best approach to me. Granted, if you are set on going with that approach, provide us with some code so we can try to figure out why the UITableView isn't responding to touches.
I am trying to use a UIAlertView essentially as a label (no title or buttons, just display text) for aesthetic purposes. I want to be able to continue to use everything else in the app (touch other buttons, etc.) while the alert view is being shown. Unfortunately, I cannot seem to invoke touchesBegan or a selector using a UITapGestureRecognizer while the alert view is shown. These both work when the alert view is not shown, but it seems like the alert view disables detection of any touches (other than touching its own buttons if it had them).
Does anyone know a way I could work around this? Even if I was to create a UILabel and set its background to the alert view image that would work.
Thanks for your help.
The alert view puts a new window on top of the entire screen which intercepts touches. It's expressly designed to prevent you from doing what you're trying to do. Why are you trying to abuse alerts in this manner anyway? It's generally a bad idea to take existing UI and use them in non-standard ways, as well as a possible reason to get rejected.
Your best bet is to just draw the "alert view" yourself, either in code or as a pre-baked image. Unfortunately this means you cannot leverage the built-in code that draws UIAlertView, but it's probably best that you don't try to appear identical to a UIAlertView anyway.
In a UIAlertView I need to align buttons into rows so that there are either 2 in each row or 3 in each row. This is for an appstore app so I need to use documented methods. So obviously I can't use setNumberOfRows: for this. Suggestions on how I could achieve the same effect?
You can't customize UIAlert to any meaningful extent.
In any case, it sounds like you don't want an alert view but rather sheet or a modal view.
UIAlert is restricted for a reason. It's supposed to present a simple, standardized (and easy to call) view to draw the users attention to a specific issue. You don't want to use it for complex choices.
If you create your own view and present it modally. It will popup above the other views just like an alert but you will be able to customize its appearance and behavior as you wish.