1

I want to add checkbox view to my UIAlertView. I have made the view in which the button will be placed on :

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 50)];
[buttonCheck setImage:[UIImage imageNamed:@"btn_check_off_holo_light.png"] forState:UIControlStateNormal];

[buttonCheck addTarget:self action:@selector(agreementCheck) forControlEvents:UIControlEventTouchUpInside];

[view addSubview:buttonCheck];

Then I call the UIAlertview

UIAlertView *alertSeat = [[UIAlertView alloc] initWithTitle:[language stringForKey:@"WARNING_SEAT_TITLE"] message:[NSString stringWithFormat:@"%@\n%@\n\n%@", [language stringForKey:@"WARNING_SEAT_SELECTION"], [language  stringForKey:@"WARNING_SEAT_SELECTION2"], [language stringForKey:@"WARNING_SEAT_CONTENT_MESSAGE"]] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];

[alertSeat setValue:view forKey:@"accessoryView"];
[alertSeat show];

This works well on IOS above 7.0 and above, but gives me following error on IOS 6.1 and below :

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key accessoryView.'

Have tried searching in Google, but can't find solution. Any help would be appreciated. Thanks

Karate_Dog
  • 1,265
  • 5
  • 20
  • 37
  • `UIAlertView`s are meant to be used as is and you shouldn't be messing with the view hierarchy. – Popeye Oct 16 '14 at 08:50
  • check the outlets and ibactions connected correctly – Arun Oct 16 '14 at 08:50
  • @Popeye : So basically you are saying that adding a view inside alertview violates its purpose as to only show alert pop up notification ? – Karate_Dog Oct 16 '14 at 09:03
  • 1
    For whatever reason Apple restrict what you can do with a `UIAlertView` and there is a note in the documentation that states that a `UIAlertView` can't be subclassed and you shouldn't mess with the view hierarchy and that it should be used as is. Violating this will get your app rejected from the app store. This make `Light Yagami` recommendation to subclass it highly wrong. There are however plenty of third party libraries out there that can be used. – Popeye Oct 16 '14 at 09:26

1 Answers1

2

The iOS version before 6 is not the same with the 7. you can see this pagecustom alter view

the best solution is use the lib named custom alter

Community
  • 1
  • 1
Feng Lin
  • 670
  • 4
  • 8