Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当没有显示viewController时,如何将cocoapod转换为typescript?_Javascript_Objective C_Typescript_Cocoapods_Nativescript - Fatal编程技术网

Javascript 当没有显示viewController时,如何将cocoapod转换为typescript?

Javascript 当没有显示viewController时,如何将cocoapod转换为typescript?,javascript,objective-c,typescript,cocoapods,nativescript,Javascript,Objective C,Typescript,Cocoapods,Nativescript,在Nathan Walker编写的关于egghead.io的ns教程中使用了objc库之后,我想测试一下我的新技能。我已经在上启动了相同的转换过程 该pod似乎不公开UIView或viewController本身,而是在管理器中。您建议我如何将其添加到appWindow.rootViewController 原始代码: MDCSnackbarMessage *message = [[MDCSnackbarMessage alloc] init]; message.text = @"How muc

在Nathan Walker编写的关于egghead.io的ns教程中使用了objc库之后,我想测试一下我的新技能。我已经在上启动了相同的转换过程

该pod似乎不公开UIView或viewController本身,而是在管理器中。您建议我如何将其添加到appWindow.rootViewController

原始代码:

MDCSnackbarMessage *message = [[MDCSnackbarMessage alloc] init];
message.text = @"How much wood would a woodchuck chuck if a woodchuck could chuck wood?";
[MDCSnackbarManager showMessage:message];
我的打字稿:

constuctor(){
    this._message = MDCSnackbarMessage.alloc().init(); 
}

public showMessage(m:string){
    this._message.text = m;
    MDCSnackbarManager.showMessage(this._message)
}
真管用!但当我从我的应用程序控制器调用它时,我的应用程序中没有显示任何内容。因此,我的第一个猜测是深入研究MDCSnackBarManager代码,找到一种设置容器的方法。我发现它:

所以,我试过这个:

它与下面的消息一起崩溃。如何确保管理器/消息正确添加到根视图

*** JavaScript call stack:
    (
        0   UIApplicationMain@[native code]
        1   start@file:///app/tns_modules/tns-core-modules/application/application.js:251:26
        2   bootstrapApp@file:///app/tns_modules/nativescript-angular/platform-common.js:68:28
        3   bootstrapModule@file:///app/tns_modules/nativescript-angular/platform-common.js:56:26
        4   anonymous@file:///app/main.js:4:57
        5   evaluate@[native code]
        6   moduleEvaluation@:1:11
        7   @:7:50
        8   promiseReactionJob@:1:11
    )
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationControllerImpl bounds]: unrecognized selector sent to instance 0x7ff366920a00'
    *** First throw call stack:
    (
        0   CoreFoundation                      0x000000010e7f9d4b __exceptionPreprocess + 171
        1   libobjc.A.dylib                     0x000000010e25b21e objc_exception_throw + 48
        2   CoreFoundation                      0x000000010e869f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
        3   CoreFoundation                      0x000000010e77f005 ___forwarding___ + 1013
        4   CoreFoundation                      0x000000010e80ca08 __forwarding_prep_1___ + 120
        5   MaterialComponents                  0x000000010aced0d4 -[MDCSnackbarManagerInternal activateOverlay:] + 612
        6   MaterialComponents                  0x000000010acebeeb -[MDCSnackbarManagerInternal displaySnackbarViewForMessage:] + 1163
        7   MaterialComponents                  0x000000010aceba40 -[MDCSnackbarManagerInternal showNextMessageIfNecessaryMainThread] + 496
        8   MaterialComponents                  0x000000010aced917 -[MDCSnackbarManagerInternal showMessageMainThread:] + 487
        9   MaterialComponents                  0x000000010aceec34 __34+[MDCSnackbarManager showMessage:]_block_invoke + 84
        10  libdispatch.dylib                   0x000000010f4ff808 _dispatch_call_block_and_release + 12
        11  libdispatch.dylib                   0x000000010f52112e _dispatch_client_callout + 8
        12  libdispatch.dylib                   0x000000010f5084fb _dispatch_main_queue_callback_4CF + 1054
        13  CoreFoundation                      0x000000010e7bde49 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
        14  CoreFoundation                      0x000000010e78337d __CFRunLoopRun + 2205
        15  CoreFoundation                      0x000000010e782884 CFRunLoopRunSpecific + 420
        16  GraphicsServices                    0x0000000111619a6f GSEventRunModal + 161
        17  UIKit                               0x000000010c015c68 UIApplicationMain + 159
        18  NativeScript                        0x000000010b48797d ffi_call_unix64 + 85
        19  ???                                 0x000000012a5fdf70 0x0 + 5005893488
    )
Mar 27 16:50:04 PODMB0079 SpringBoard[5820]: [KeyboardArbiter] HW kbd: Failed to set (null) as keyboard focus
Mar 27 16:50:04 PODMB0079 com.apple.CoreSimulator.SimDevice.CB2CCBE6-20D1-4283-908C-2232692E7AC0.launchd_sim[5804] (UIKitApplication:org.nativescript.podtest[0x8461][7291]): Service exited due to Abort trap: 6

我将根viewController而不是视图传递给方法。相反,它应该是这样的:

MDCSnackbarManager.setPresentationHostView(rootVC().view); //duh
const rootVC = function(){
    let appWindow = UIApplication.sharedApplication.keyWindow;
    return appWindow.rootViewController;
}

我是个白痴。我传递的是viewController,而不是视图。因此,通过rootVC.view这门课程可能也会有所帮助-对于普通NS和Angular+NativeScript来说有很多好处。。。我刚刚意识到你提到了沃克在书呆子上的一课:无论如何,如果你想深入挖掘,他的课程链接是值得的。
*** JavaScript call stack:
    (
        0   UIApplicationMain@[native code]
        1   start@file:///app/tns_modules/tns-core-modules/application/application.js:251:26
        2   bootstrapApp@file:///app/tns_modules/nativescript-angular/platform-common.js:68:28
        3   bootstrapModule@file:///app/tns_modules/nativescript-angular/platform-common.js:56:26
        4   anonymous@file:///app/main.js:4:57
        5   evaluate@[native code]
        6   moduleEvaluation@:1:11
        7   @:7:50
        8   promiseReactionJob@:1:11
    )
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationControllerImpl bounds]: unrecognized selector sent to instance 0x7ff366920a00'
    *** First throw call stack:
    (
        0   CoreFoundation                      0x000000010e7f9d4b __exceptionPreprocess + 171
        1   libobjc.A.dylib                     0x000000010e25b21e objc_exception_throw + 48
        2   CoreFoundation                      0x000000010e869f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
        3   CoreFoundation                      0x000000010e77f005 ___forwarding___ + 1013
        4   CoreFoundation                      0x000000010e80ca08 __forwarding_prep_1___ + 120
        5   MaterialComponents                  0x000000010aced0d4 -[MDCSnackbarManagerInternal activateOverlay:] + 612
        6   MaterialComponents                  0x000000010acebeeb -[MDCSnackbarManagerInternal displaySnackbarViewForMessage:] + 1163
        7   MaterialComponents                  0x000000010aceba40 -[MDCSnackbarManagerInternal showNextMessageIfNecessaryMainThread] + 496
        8   MaterialComponents                  0x000000010aced917 -[MDCSnackbarManagerInternal showMessageMainThread:] + 487
        9   MaterialComponents                  0x000000010aceec34 __34+[MDCSnackbarManager showMessage:]_block_invoke + 84
        10  libdispatch.dylib                   0x000000010f4ff808 _dispatch_call_block_and_release + 12
        11  libdispatch.dylib                   0x000000010f52112e _dispatch_client_callout + 8
        12  libdispatch.dylib                   0x000000010f5084fb _dispatch_main_queue_callback_4CF + 1054
        13  CoreFoundation                      0x000000010e7bde49 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
        14  CoreFoundation                      0x000000010e78337d __CFRunLoopRun + 2205
        15  CoreFoundation                      0x000000010e782884 CFRunLoopRunSpecific + 420
        16  GraphicsServices                    0x0000000111619a6f GSEventRunModal + 161
        17  UIKit                               0x000000010c015c68 UIApplicationMain + 159
        18  NativeScript                        0x000000010b48797d ffi_call_unix64 + 85
        19  ???                                 0x000000012a5fdf70 0x0 + 5005893488
    )
Mar 27 16:50:04 PODMB0079 SpringBoard[5820]: [KeyboardArbiter] HW kbd: Failed to set (null) as keyboard focus
Mar 27 16:50:04 PODMB0079 com.apple.CoreSimulator.SimDevice.CB2CCBE6-20D1-4283-908C-2232692E7AC0.launchd_sim[5804] (UIKitApplication:org.nativescript.podtest[0x8461][7291]): Service exited due to Abort trap: 6
MDCSnackbarManager.setPresentationHostView(rootVC().view); //duh
const rootVC = function(){
    let appWindow = UIApplication.sharedApplication.keyWindow;
    return appWindow.rootViewController;
}