skywinder / ActionSheetPicker-3.0

Quickly reproduce the dropdown UIPickerView / ActionSheet functionality on iOS.
http://skywinder.github.io/ActionSheetPicker-3.0
BSD 3-Clause "New" or "Revised" License
3.4k stars 740 forks source link

crash on Action sheet #483

Closed maulikshah09 closed 4 years ago

maulikshah09 commented 4 years ago
  1. add pod pod 'ActionSheetPicker-3.0'

  2. goto terminal and pod install from terminal

  3. import ActionSheetPicker_3_0

  4. copy paste code.

@IBAction func btnSignupPress(_ sender: UIButton) {
        //appDelegate.registerNotification()
        appDelegate.flag = 1
     ActionSheetStringPicker.show(withTitle: "Picker from navigation bar",
                                         rows: ["One", "Two", "A lot"],
                                         initialSelection: 1,
                                         doneBlock: { picker, value, index in
                                            print("picker = \(String(describing: picker))")
                                            print("value = \(value)")
                                            print("index = \(String(describing: index))")
                                            return
                                         },
                                         cancel: { picker in
                                            return
                                         },
                                         origin: sender)
    }

and crash what is the issue.Don't know.

'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'

MyHealthTracker[6224:125016] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48
    2   Foundation                          0x00007fff2577d523 -[NSPlaceholderString initWithValidatedFormat:validFormatSpecifiers:locale:arguments:error:] + 0
    3   Foundation                          0x00007fff2577606b +[NSString stringWithString:] + 45
    4   UIFoundation                        0x00007fff4754444b __NSNormalizedLanguage + 97
    5   UIFoundation                        0x00007fff475443d3 ____NSNormalizedPreferredLanguage_block_invoke + 49
    6   libdispatch.dylib                   0x00000001052a3d48 _dispatch_client_callout + 8
    7   libdispatch.dylib                   0x00000001052a5297 _dispatch_once_callout + 66
    8   UIFoundation                        0x00007fff475440b0 -[NSParagraphArbitrator lineBreakContextBeforeIndex:lineFragmentWidth:range:] + 2859
    9   UIFoundation                        0x00007fff475694c4 -[NSCoreTypesetter _stringDrawingCoreTextEngineWithOriginalString:rect:padding:graphicsContext:forceClipping:attributes:stringDrawingOptions:drawingContext:wantsTextLineFragments:validatedAttributedString:firstNonRenderedCharacterIndex:foundSoftHyphenAtEOL:enginePathUsed:] + 5554
    10  UIFoundation                        0x00007fff47562a67 __NSStringDrawingEngine + 5999
    11  UIFoundation                        0x00007fff475643a6 -[NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:] + 757
    12  UIKitCore                           0x00007fff47a6123d -[UIButton _deriveTitleRect:imageRect:fromContentRect:calculatePositionForEmptyTitle:] + 1864
    13  UIKitCore                           0x00007fff47a609d2 -[UIButton _titleRectForContentRect:calculatePositionForEmptyTitle:] + 287
    14  UIKitCore                           0x00007fff47a60a79 -[UIButton titleRectForContentRect:] + 49
    15  UIKitCore                           0x00007fff47a661a6 -[UIButton _setupTitleViewRequestingLayout:] + 156
    16  UIKitCore                           0x00007fff47a65304 -[UIButton _updateTitleView] + 269
    17  UIKitCore                           0x00007fff47a6567d -[UIButton layoutSubviews] + 214
    18  UIKitCore                           0x00007fff485784bd -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
    19  QuartzCore                          0x00007fff2b131db1 -[CALayer layoutSublayers] + 255
    20  QuartzCore                          0x00007fff2b137fa3 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
    21  UIKitCore                           0x00007fff48563635 -[UIView(Hierarchy) layoutBelowIfNeeded] + 980
    22  UIKitCore                           0x00007fff476be9c8 -[_UIButtonBarButtonVisualProviderIOS _configureImageOrTitleFromBarButtonItem:compact:] + 973
    23  UIKitCore                           0x00007fff476c1b79 -[_UIButtonBarButtonVisualProviderIOS configureButton:fromBarButtonItem:] + 322
    24  UIKitCore                           0x00007fff476bfa88 -[_UIButtonBarButtonVisualProviderIOS configureButton:withAppearanceDelegate:fromBarItem:] + 114
    25  UIKitCore                           0x00007fff476bbac8 -[_UIButtonBarButton _configureFromBarItem:appearanceDelegate:isBackButton:] + 83
    26  UIKitCore                           0x00007fff476bb664 -[_UIButtonBarButton configureFromBarItem:withAppearanceDelegate:] + 53
    27  UIKitCore                           0x00007fff476b8ad7 -[_UIButtonBar _updatedViewForBarButtonItem:withView:] + 435
    28  UIKitCore                           0x00007fff476b760d __32-[_UIButtonBar _newGroupLayout:]_block_invoke + 82
    29  UIKitCore                           0x00007fff476c4300 -[_UIButtonBarItemLayout _updateItemView] + 53
    30  UIKitCore                           0x00007fff476c48e1 -[_UIButtonBarItemLayout _configure] + 39
    31  UIKitCore                           0x00007fff476c336b -[_UIButtonBarLayout configure] + 51
    32  UIKitCore                           0x00007fff476c34ce -[_UIButtonBarLayout addLayoutViews:] + 49
    33  UIKitCore                           0x00007fff476c6a18 -[_UIButtonBarItemGroupLayout _iterateConfiguredLayouts:] + 228
    34  UIKitCore                           0x00007fff476c6af4 -[_UIButtonBarItemGroupLayout _addLayoutViews:] + 111
    35  UIKitCore                           0x00007fff476c3432 -[_UIButtonBarLayout addLayoutViews:layoutGuides:constraintsToActivate:constraintsToDeactivate:] + 111
    36  UIKitCore                           0x00007fff476b7d78 -[_UIButtonBar _layoutBar] + 1841
    37  UIKitCore                           0x00007fff476baa48 -[_UIButtonBarStackView updateConstraints] + 48
    38  UIKitCore                           0x00007fff48497464 -[UIView(AdditionalLayoutSupport) _sendUpdateConstraintsIfNecessaryForSecondPass:] + 489
    39  UIKitCore                           0x00007fff48497a38 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 1193
    40  UIKitCore                           0x00007fff484978c5 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 822
    41  UIKitCore                           0x00007fff484978c5 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 822
    42  Foundation                          0x00007fff258d8263 -[NSISEngine withBehaviors:performModifications:] + 84
    43  UIKitCore                           0x00007fff484981da __100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke + 85
    44  UIKitCore                           0x00007fff484969e6 -[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 104
    45  UIKitCore                           0x00007fff48497d35 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 154
    46  UIKitCore                           0x00007fff48498c51 -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] + 393
    47  UIKitCore                           0x00007fff48563fda -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 272
    48  UIKitCore                           0x00007fff48578536 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2599
    49  QuartzCore                          0x00007fff2b131db1 -[CALayer layoutSublayers] + 255
    50  QuartzCore                          0x00007fff2b137fa3 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
    51  QuartzCore                          0x00007fff2b1438da _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
    52  QuartzCore                          0x00007fff2b08a848 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
    53  QuartzCore                          0x00007fff2b0bfb51 _ZN2CA11Transaction6commitEv + 643
    54  QuartzCore                          0x00007fff2b0c04ba _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 76
    55  CoreFoundation                      0x00007fff23bd3867 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    56  CoreFoundation                      0x00007fff23bce2fe __CFRunLoopDoObservers + 430
    57  CoreFoundation                      0x00007fff23bce97a __CFRunLoopRun + 1514
    58  CoreFoundation                      0x00007fff23bce066 CFRunLoopRunSpecific + 438
    59  GraphicsServices                    0x00007fff384c0bb0 GSEventRunModal + 65
    60  UIKitCore                           0x00007fff48092d4d UIApplicationMain + 1621
    61  MyHealthTracker                     0x0000000103ed250b main + 75
    62  libdyld.dylib                       0x00007fff5227ec25 start + 1
    63  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
maulikshah09 commented 4 years ago

Got it...Localization issue.. if not localize then work perfectly .How can i Solve this.. I know it's localisation issue..

calling this mehod...Bundle.setLanguage("ar") or Bundle.setLanguage("en")

import Foundation
import ObjectiveC
import UIKit

var kBundleKey: UInt8 = 0
var isLangDirectionRTL = false
class BundleEx: Bundle {

    override func localizedString(forKey key: String, value: String?, table tableName: String?) -> String {
        let bundle: Bundle? = objc_getAssociatedObject(self, &kBundleKey) as? Bundle
        if bundle != nil {
            return NSLocalizedString(value!, tableName: nil, bundle: bundle!, value: "", comment: "")
        }
        else {
            return super.localizedString(forKey: key, value: value, table: tableName)
        }
    }
}

extension Bundle {

    class func setLanguage(_ language: String?) {
        var onceToken = 0
        if (onceToken == 0) {
            /* TODO: move below code to a static variable initializer (dispatch_once is deprecated) */
            object_setClass(Bundle.main, BundleEx.self)
        }
        UserDefaults.standard.set(language, forKey: UserDefaultKey.AppleLanguage.rawValue)
        UserDefaults.standard.synchronize()

        onceToken = 1
        let isLanguageRTL: Bool = self.isLanguageRTL(language)
        if isLanguageRTL {
            isLangDirectionRTL = true
            if UIView().responds(to: #selector(setter: UIView.semanticContentAttribute)) {
                UIView.appearance().semanticContentAttribute = .forceRightToLeft
            }
        }
        else {
            isLangDirectionRTL = false
            if UIView().responds(to: #selector(setter: UIView.semanticContentAttribute)) {
                UIView.appearance().semanticContentAttribute = .forceLeftToRight
            }
        }

//        UserDefaults.standard.set(isLanguageRTL, forKey: "AppleTextDirection")
//        UserDefaults.standard.set(isLanguageRTL, forKey: "NSForceRightToLeftWritingDirection")
//        UserDefaults.standard.synchronize()
        let value = Bundle(path: Bundle.main.path(forResource: language, ofType: "lproj") ?? "")
        objc_setAssociatedObject(Bundle.main, &kBundleKey, value, .OBJC_ASSOCIATION_RETAIN)
    }

    class func isLanguageRTL(_ languageCode: String?) -> Bool {
        return NSLocale.characterDirection(forLanguage: languageCode ?? "") == .rightToLeft
    }
}
skywinder commented 4 years ago

Hi. as I can see it caused by outside changes. I belive you have to set not nil argument as it says: 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'