How to add more than eight buttons in a UIAlertView? - iphone

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.

Related

Rearranging UIAlertView's button layout

just a quick question.
Is it possible to change layout of UIAlertView's buttons? Two of them look nice
However three buttons and more waste so much space with, is there any way to re arrange them? So they are in horizontal order like with two buttons?
Default layout is :
Only thing that come to my mind is to create view, add buttons on that view and add it as a subview to UIAlertView...
You'll have to create your own custom AlertView I'm afraid:
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.
- Apple
In regard to custom UIAlertViews, the following link might be what you're after - https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets.
Following is best link for custom UIAlertView that you want .
https://github.com/stavash/UIBAlertView
https://github.com/TomSwift/TSAlertView
For more get custom UIAlertView this is The Best site for any Custom Controls.
Choose any one form above link and add it with your requirement.

iPhone application - pop up dialogue - sort of

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.

Changing number of button rows in UIAlertView using public API's

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.

Is it possable to change the frame of a UIAlertView

I want to move a UIAlertView's frame because I am adding a UITextFied to it and when the keypad is hiding the Cancel and Ok buttons that are apart of my alertView
Do you just want to move the entire alertview around or move the views inside the button around? If the former, UIAlertViews are a UIView subclass. Just use the .frame property.
If its the latter, I would recommend against doing so. Instead, I'd probably suggest a modal view of some sorts. And to file a radar with Apple about making this possible.
Basically, you'd have to subclass UIAlertView to change the view itself. However, it needs pointing out that UIAlertViews are very fragile (the buttons in the view are a private class and, IIRC, the internals have been changed around before).
But if you must, as it stands right now, you're going to need to use a hack. UIAlertView is a UIView subclass and that you can iterate through the subviews as needed. There are only going to be three kinds of views in your view—and two kinds of views (message and title labels, textfields you add in) are public classes that you can check against with - isKindOfClass:.
Alternately, there's also "Make the alert have a message that takes up two lines and add the alertview in so that it covers that subview" at the expense of having a mssage in the alert. Just as hacky, in a different way.

More than 1 button on the left side of a NavigationBar

Is it possible?
I have a UINavigationBar that I'd like to have an 'edit' button next to the 'back' button. From what I've read you can only have one or the other, which makes no sense as they are separate properties of the navigationItem object(backBarButtonItem and leftBarButtonItem).
I'm assuming you have to somehow insert a custom UIView into the UINavigationBar. I'm looking into this option and if no better solution is given then I'll outline this method.
The short answer is:
Yes, you have to add your own UIButton views (or other UIControl subclasses) to the navigation controller, yourself. So, ignore the custom *ButtonItem properties and roll it yourself.
A little more involved answer is:
Apple makes it very easy to follow their HIG guidelines, but you're on your own if you want to break them or customize. In this case, only one button is allowed, because the actual hit region is bigger than the size of the displayed button--much easier to hit from a usability standpoint.
Extraneous:
btw, there is a subtle distinction between left/rightBarButtonItem and backBarButtonItem. left/right is specified on the current UIViewController. However back is specified by the previous UIViewController.
Using a custom view is indeed your only option here. The UINavigationBar is not terribly flexible. What you will need to do is create a UIView that contains UIButtons. Be sure you realize that if you use a custom view, you gain none of the automatic behaviors of the backBarButtonItem; you have to create your own IBActions, and the graphics for the buttons as well.
On a related note, I'm not sure this is the best idea. It's usually wise to stick to Apple's UI guidelines; is there no where else you can put the edit button? The right side of the bar, for example?
While #Kelvin's answer works for pre iOS 5, if you're using iOS 5+ there is now a leftBarButtonItems array property. Note that you also must set leftItemsSupplementBackButton to true.