6

I want to add the UITableView inside the alert view.

I have tried to add a table view as a sub view of alert view, it's not working. Can you give me some code or sample link for that?

How can I do that?

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Pugalmuni
  • 9,350
  • 8
  • 56
  • 97

5 Answers5

8

Try any one of these pages :

http://zpasternack.blogspot.com/2010/10/stupid-uialertview-tricks-part-deux.html

https://github.com/blommegard/SBTableAlert

elcuco
  • 8,948
  • 9
  • 47
  • 69
Karthikeyan
  • 1,790
  • 12
  • 19
  • 5
    2 dead links and other 2 moved. This is why you should add code to the answers, not only links. – User May 27 '14 at 12:01
5

Its working in my case

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"click for submission \n\n\n\n "delegate:self  cancelButtonTitle:@"click for submission"
otherButtonTitles:nil];

    table = [[UITableView alloc]initWithFrame:CGRectMake(10, 40, 264, 120)];
    table.delegate = self;
    table.dataSource = self;
    [alert addSubview:table];

    [alert show];

    [table release];

    [alert release];        
Neha
  • 51
  • 1
  • 1
  • Please dont forget to add the UITableView specific functions like cellForRowatIndexPath etc. It would cause a SIGABRT. – Maurice May 29 '13 at 19:59
  • This code is not working with iOS 7.. How to fix this in iOS 7 – Mano Oct 25 '13 at 09:27
  • Meddling with the UIAlertView view hierarchy is expressly disallowed according to Apple's documentation: ["The view hierarchy for this class is private and must not be modified".](https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html) – David Hunt Mar 24 '14 at 23:07
3

Is this really what you want?

An alert is very obtrusive, and quite alarming to the user. Alerts are modal and should be use with great discretion. Maybe one of these could be a better solutions:

  • Navigate to a new screen with the options in a table view there. Like most of the Settings app do.
  • Use a UISegmentedControl, like for example in the settings of a WiFi network.
  • Have the options in a UIPopoverController if on iPad.
  • Rephrase the option so a UISwitch is the logical control.
PeyloW
  • 36,742
  • 12
  • 80
  • 99
2

Instead of UIAlertView + UITableView is much better to use UIActionSheet.

János
  • 32,867
  • 38
  • 193
  • 353
0

you can use CAAlertView "https://github.com/chandanankush/CAAlertView" for both tableView listing and datePicker

Chandan
  • 500
  • 3
  • 10