-2

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 ??

Jimbo
  • 25,790
  • 15
  • 86
  • 131
kunj1986
  • 13
  • 1
  • Nopes... You can't. You had to created the custom view with works in the same way as UIAlertView. Since increasing the no. of buttons, will not allow the alert to scroll. – Ajay Sharma Jun 21 '13 at 10:23
  • go with customview instead of alertview – Girish Jun 21 '13 at 10:24
  • Apple docs advice if you are using more than two buttons you should really use `UIActionSheet` this is not a requirement just a recommendation. – Popeye Jun 21 '13 at 10:29

6 Answers6

2

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)

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • I always find that everyone finds a lot of confusion around `UIAlertView` subclassing. Whilst I totally agree that if your going to be messing with `UIAlertView`s it would be better to just create your own version using `UIView` or something, but the Apple docs do specify that subclassing is `@interface myAlertView : UIAlertView` and not using `addSubview` it is not recommended but apple do still allow the use of `addSubview` because it isn't subclassing. +1 for links to apple docs – Popeye Jun 21 '13 at 10:33
1

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!

Vinayak Kini
  • 2,919
  • 21
  • 35
0

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.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
0

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....

DevCali
  • 398
  • 6
  • 20
0

Just move ahead with CustomView, Otherwise not possible with UIAlertView to meet up with your requirement :

Reference links :

  1. http://iphonedevelopment.blogspot.in/2010/05/custom-alert-views.html
  2. http://iosdevtricks.blogspot.in/2013/04/creating-custom-alert-view-for-iphone.html
  3. https://stackoverflow.com/a/6965828/434898
Community
  • 1
  • 1
amit rajput
  • 18
  • 12
-3

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.

Alex Terente
  • 12,006
  • 5
  • 51
  • 71
  • 1
    The question was how to add more that 8 button to a `UIAlertView` not how to use the `UIAlertView`. – rckoenes Jun 21 '13 at 10:21