iOS 8 | Add image to UIActionSheet's button - ios

In iOS 7 and below , I added a custom image on UIActionSheet's buttons , but it seems it doesn't work on iOS 8 and crashes ! , here is the codes :
[[[sheet valueForKey:#"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:#"image"] forState:UIControlStateNormal];
Crashes due to :
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIActionSheet 0x16d4abf0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key _buttons.'
*** First throw call stack:

It was always wrong to mess with the look / details of a UIActionSheet. The correct solution, both on iOS 7 and iOS 8, is to use a presented view controller whose view looks like an action sheet - but now it's your view and you can configure it however you like.

UIActionSheet is deprecated in iOS8, you may want to use the new UIAlertController with the UIAlertControllerStyleActionSheet style.
I agree with matt, you should not use dirty ways to custom an UIActionSheet, the safest and nicest way to have an UIActionSheet looks like you want to is to create yours.

Related

App crashes when I click on side bar menu

Before it worked, when I made the update iOS 13 and updated xCode to 11, I am not able to use the side bar. The application is using the pod SideMenuController and when I click on the icon of side menu to show it, it crashes and shows me this message:
Assertion failure in -[UIApplication _createStatusBarWithRequestedStyle:orientation:hidden:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3899.22.15/UIApplication.m:5311
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.'
I will answer why didn't I show the code, because I didn't made it, the engineer that was before me made it with a pod named SideMenuController. So I'm not familiar with the project or the code inside. I did a lot of research and I fixed it and I wanted to share the solution with you. ( PS: I don't know how it worked ) in the description of the pod, I needed to comment this line:
SideMenuController.preferences.animating.transitionAnimator = FadeAnimator.self
and another line to change from :
SideMenuController.preferences.animating.statusBarBehaviour = .horizontalPan
To this line :
SideMenuController.preferences.animating.statusBarBehaviour = .showUnderlay
And it worked like magic, Thank you guys

ios-13-App crashes when setting UIColor as BackgroundImage

I am trying to set searchbar background image with UIColor. My code is working fine in ios 12.x but It is crashing in ios 13. My code is as follows.
[[UISearchBar appearance] setScopeBarBackgroundImage:[UIImage imageWithCGImage:(__bridge CGImageRef)([UIColor clearColor])]];
The crash log says Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'imageRef passed is not a CGImageRef'
Can anyone suggest alternative way to resolve crash?
In your code you're casting a UIColor object to a CGImageRef. This doesn't make sense, and I don't know why it would have worked in iOS 12.
You probably want to just make a UIImage filled with a solid color. Something like this:
https://gist.github.com/uknowho/5915365

iOS App crashes after migrating to swift3 during navigation

I have migrated my project to Swift3 and after conversion the app crashes whenever I click on any button which loads a new screen. The crash happens in the assembly code so am not able to figure out what's the issue. Control leaves the existing class then goes to assembly language and then crash just before loading the new screen.
This is the error message am getting
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue pointSize]: unrecognized selector sent to instance 0x61000005fb00'
Crash is not happening in any specific code so its difficult identify the error. Please help me to figure this out.
You maybe have a outlet from your storyboard (label, textfield, uiButton...) that is not map anymore in your controller. You should check each component to see if you didn't delete the reference in the controller and no in the storyboard...

Custom Segue - unrecognized selector sent to instance - setUseDefaultModalPresentationStyle

I'm using this custom segue. It works perfectly on iOS8+, however, on iOS 7, I get this error.
2015-10-09 13:59:02.891 APPNAME[1790:60b] -[APPNAME.AFBlurSegue setUseDefaultModalPresentationStyle:]: unrecognized selector sent to instance 0x15ddafe0
2015-10-09 13:59:02.901 APPNAME[1790:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[APPNAME.AFBlurSegue setUseDefaultModalPresentationStyle:]: unrecognized selector sent to instance 0x15ddafe0'
*** First throw call stack:
(0x2e5c6f83 0x38d77ccf 0x2e5ca917 0x2e5c9203 0x2e518768 0x312c0381 0x312b63fb 0x30e19037 0x30e18fd7 0x30e18fb1 0x30e04717 0x30e18a2f 0x30e18701 0x30e136cb 0x30de88cd 0x30de6f77 0x2e59220b 0x2e5916db 0x2e58fecf 0x2e4faebf 0x2e4faca3 0x33400663 0x30e4714d 0x13e65c 0x39284ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The problem is, the crash is vague. I even tried putting breakpoints everywhere and tried to catch any errors thrown. However, it still doesn't point to where the error could be.
The fact that it seems like an argument/selector error, I suspect this might be a Swift 2 error. The only place I can find a reference to setUseDefaultModalPresentationStyle is here.
Any help would be greatly appreciated!
Try set Segue setting to Custom on the segue in storyboard, and set the style programmatically:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIViewController *destination = segue.destinationViewController;
destination.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
}
This happens because this library uses the UIVisualEffectView to get the blur effect. Unfortunately UIVisualEffectView is only available in iOS 8 and up.
See the documentation for more information.
Unfortunately, if you want to use your fancy blur transitions, your app wont be compatible with iOS 7 and below, which isn't that much of a problem, since currently only 10% devices have iOS below iOS 8.
More info here
Solution:
You could solve this using an older version of this library which does not yet use the UIVisualEffectView but instead uses UIImage+ImageEffects.m to get the blur effect.

NSInvalidUnarchiveOperationException, UIStoryboardShowSegueTemplate

I am using storyboard in which there is UINavigationController. View controllers are popped and pushed.
The issue is , when i push a UIViewController i take the exception on iOS 7, it works fine on iOS 8.
Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named UIStoryboardShowSegueTemplate'
What can be the problem?
Could you please help
As i am also getting the same issue with my project. I get this resolved by rechecking all segues i defined in the app. Make sure all segues will have some action like push/pop/modal.
If not then on that controller app will crash. Please check below snapshot which you will find in your storyboard.
Refer a solution on below link.
"Could not instantiate class named UIStoryboardShowSegueTemplate" - how can I make a Storyboard happy with iOS 7 and iOS 8?

Resources