선택한 행의 Apple Watch Table 충돌

드레이크

Xamarin을 사용하여 Apple Watch 앱을 개발하고 있습니다. 테이블 (WKInterfaceTable)을 추가하고 코드 숨김으로 채 웁니다. 그러나 행을 클릭하면 앱이 즉시 충돌합니다.

여기까지 이해하기 위해 실제로 스토리 보드 XML 파일을 수동으로 편집했습니다. 스토리 보드에 테이블을 끌어다 놓는 것만으로는 작동하지 않기 때문입니다. 다음은 XML입니다.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="6221" systemVersion="14A389" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="AgC-eL-Hgc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6213"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="3734"/>
</dependencies>
<scenes>
    <!--Interface Controller-->
    <scene sceneID="aou-V4-d1y">
        <objects>
            <controller id="AgC-eL-Hgc" title="Favorites" customClass="InterfaceController" customModuleProvider="">
                <items>
                    <table alignment="left" id="nXC-Mh-TYy">
                        <items>
                            <tableRow identifier="default" id="zJA-dk-zIT" customClass="FavoriteRowController">
                                <group key="rootItem" width="1" height="40" alignment="left" spacing="6" id="ASs-9x-fCK">
                                    <items>
                                        <imageView width="35" height="35" alignment="left" verticalAlignment="center" image="Door" id="rac-gq-1kM"/>
                                        <label alignment="left" verticalAlignment="center" text="Location" id="jkO-KQ-vGr"/>
                                    </items>
                                    <color key="backgroundColor" red="0.93625843524932861" green="0.94465947151184082" blue="0.98500943183898926" alpha="0.14000000000000001" colorSpace="custom" customColorSpace="sRGB"/>
                                    <edgeInsets key="margins" left="2" right="2" top="2" bottom="2"/>
                                </group>
                                <connections>
                                    <outlet property="RowLabel" destination="jkO-KQ-vGr" id="Hcb-P2-F5Q"/>
                                </connections>
                            </tableRow>
                        </items>
                    </table>
                </items>
                <connections>
                    <outlet property="InterfaceTable" destination="nXC-Mh-TYy" id="4YS-uT-eWw"/>
                </connections>
            </controller>
        </objects>
        <point key="canvasLocation" x="0.0" y="0.0"/>
    </scene>
</scenes>

XML에 문제가 있습니까?

코드 InterfaceController:

public partial class InterfaceController : WKInterfaceController
{
    protected InterfaceController(IntPtr handle) : base(handle)
    {
        // Note: this .ctor should not contain any initialization logic.
    }

    public override void Awake(NSObject context)
    {
        base.Awake(context);

        this.LoadTableData();

        // Configure interface objects here.
        Console.WriteLine("{0} awake with context", this);
    }

    public override void WillActivate()
    {
        // This method is called when the watch view controller is about to be visible to the user.
        Console.WriteLine("{0} will activate", this);
    }

    public override void DidDeactivate()
    {
        // This method is called when the watch view controller is no longer visible to the user.
        Console.WriteLine("{0} did deactivate", this);
    }

    private void LoadTableData()
    {
        var cityNames = new[] { "r1", "r2", "r3", "r4", "r5" };

        InterfaceTable.SetNumberOfRows(cityNames.Length, "default");

        for (var i = 0; i < cityNames.Length; i++)
        {
            var row = (FavoriteRowController)InterfaceTable.GetRowController(i);
            row.RowLabel.SetText(cityNames[i]);
        }
    }
}

코드 InterfaceController.designer.cs:

[Register("InterfaceController")]
partial class InterfaceController
{
    [Outlet]
    public WKInterfaceTable InterfaceTable { get; set; }

    void ReleaseDesignerOutlets()
    {
        if (InterfaceTable != null)
        {
            InterfaceTable.Dispose();
            InterfaceTable = null;
        }
    }
}

코드 FavoriteRowController:

public partial class FavoriteRowController : WKInterfaceController
{
    protected FavoriteRowController(IntPtr handle) : base(handle)
    {
        // Note: this .ctor should not contain any initialization logic.
    }

    public override void Awake(NSObject context)
    {
        base.Awake(context);

        // Configure interface objects here.
        Console.WriteLine("{0} awake with context", this);
    }

    public override void WillActivate()
    {
        // This method is called when the watch view controller is about to be visible to the user.
        Console.WriteLine("{0} will activate", this);
    }

    public override void DidDeactivate()
    {
        // This method is called when the watch view controller is no longer visible to the user.
        Console.WriteLine("{0} did deactivate", this);
    }
}

코드 FavoriteRowController.designer.cs:

[Register("FavoriteRowController")]
partial class FavoriteRowController
{
    [Outlet]
    public WKInterfaceLabel RowLabel { get; set; }

    void ReleaseDesignerOutlets()
    {
    }
}

응용 프로그램 출력의 충돌 예외 :

2016-11-03 10:10:58.780 MyAppWatchExtension[16255:474000] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FavoriteRowController 0x799ec7e0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key InterfaceTable.' *** First throw call stack: ( 0 CoreFoundation 0x00383a22 __exceptionPreprocess + 194 1 libobjc.A.dylib 0x059a0e76 objc_exception_throw + 52 2 CoreFoundation 0x00383951 -[NSException raise] + 17 3 Foundation 0x013c5732 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 238 4 Foundation 0x012eac53 _NSGetUsingKeyValueGetter + 146 5 Foundation 0x012eab3b -[NSObject(NSKeyValueCoding) valueForKey:] + 282 6 WatchKit 0x04b06c16 __58-[SPRemoteInterface handlePlistDictionary:fromIdentifier:]_block_invoke.882 + 39 7 libdispatch.dylib 0x06252c4f _dispatch_call_block_and_release + 15 8 libdispatch.dylib 0x0627550f _dispatch_client_callout + 14 9 libdispatch.dylib 0x0625be31 _dispatch_main_queue_callback_4CF + 1031 10 CoreFoundation 0x00343e7e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14 11 CoreFoundation 0x00306dcf __CFRunLoopRun + 2319 12 CoreFoundation 0x0030624b CFRunLoopRunSpecific + 395 13 CoreFoundation 0x003060ab CFRunLoopRunInMode + 123 14 Foundation 0x012c5192 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 308 15 Foundation 0x012c504f -[NSRunLoop(NSRunLoop) run] + 69 16 libxpc.dylib 0x0656d8a5 _xpc_objc_main + 476 17 libxpc.dylib 0x06570175 xpc_main + 215 18 Foundation 0x01323880 +[NSXPCListener serviceListener] + 0 19 PlugInKit 0x111556b6 -[PKService run] + 954 20 WatchKit 0x04b43108 main + 148 21 libxamarin-debug.dylib 0x0584fb33 xamarin_main + 3475 22 TycoMobilePassUIiOSWatchExtension 0x001055bc xamarin_watchextension_main + 124 23 libdyld.dylib 0x062ae85d start + 1 24 ??? 0x00000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

이언 스미스

테이블을 표시 할 때가 아니라 항목을 선택할 때 충돌이 발생하면 행 선택 코드와 관련이 있다고 가정하고 거기서 시작합니다.

수행하려는 작업에 따라 여기에 두 가지 옵션이 있습니다.

DidSelectRow

행이 선택되고 일부 데이터를 조작하거나 다른보기로 이동하려는 경우 사용됩니다.

public override async void DidSelectRow(WKInterfaceTable table, nint rowIndex)
{
    var contextForNextInterfaceController = rows[(int)rowIndex]; // this depends how you have set up the table.
    Console.WriteLine($"Row selected: {rowData}");
    PushController("TheNextInterFaceController", contextForNextInterfaceController);
}

GetContextForSegue

iOS Designer 또는 Xcode에서 segue를 설정할 때 사용하므로 사용중인 다음 인터페이스 컨트롤러에 대한 컨텍스트를 설정할 수 있습니다.

public override NSObject GetContextForSegue(string segueIdentifier, WKInterfaceTable table, nint rowIndex)
{
    // Can check segueIdentifier if using more segues
    return new ContextForNextInterfaceController() // This needs to sub class NSObject
    {
        model = modelForNextInterfaceController,
    };
}

컨텍스트를 설정 한 후 다른보기로 이동할 때 컨텍스트 개체를 캐스팅하고 원하는 유형인지 확인해야합니다.

public override void Awake(NSObject context)
{
    base.Awake(context);
    Console.WriteLine("{0} awake with context", this);
    var currentContext = context as ContextForNextInterfaceController;
    if (currentContext != null)
    {
        // Do stuff with context
    }
}

인터페이스 컨트롤러 코드 또는 행 선택 코드를 게시 할 수 있다면 더 많은 도움을 드릴 수 있습니다. 또한 응용 프로그램 출력에 오류가 발생하는 경우에도 도움이 될 수 있습니다.

================================================ ========================= 업데이트

좋아, 오류 출력 FavoriteRowController에서 콘센트가 없거나 스토리 보드에 잘못된 클래스가 설정되어 있다고 말합니다 .

이 클래스는 InterfaceTable 키에 대해 키 값 코딩을 준수하지 않습니다. '

콘센트가 없거나 콘센트를 제거했지만 스토리 보드에서 링크를 제거하지 않은 경우 일반적인 오류입니다.

RowController는 InterfaceController 일 필요가 없으므로 다음과 같이 설정합니다.

코드 FavoriteRowController:

using Foundation;

namespace WatchConnectivity.OnWatchExtension
{
    public partial class FavoriteRowController : NSObject
    {
        protected FavoriteRowController()
        {
        }
    }
}

코드 FavoriteRowController.designer.cs:

using Foundation;
using System.CodeDom.Compiler;

namespace WatchConnectivity.OnWatchExtension
{
    [Register ("FavoriteRowController")]
    partial class FavoriteRowController
    {
        [Outlet]
        public WatchKit.WKInterfaceLabel RowLabel { get; set; }

        void ReleaseDesignerOutlets ()
        {
            if (RowLabel != null) {
                RowLabel.Dispose ();
                RowLabel = null;
            }
        }
    }
}

샘플 확인

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Apple Watch Extension에 HealthKit을 추가 한 후 충돌하는 앱 식별자

분류에서Dev

Apple Watch Table Controller Not Loading

분류에서Dev

Apple LLVM에서 Qt 4.8.4 QList의 이상한 충돌

분류에서Dev

Swift 3.0의 선택적 문자열로 인한 충돌

분류에서Dev

PostgreSQL의`충돌 업데이트시 선택 삽입`문장에서 선택한 행을 참조하는 방법

분류에서Dev

릴리스 빌드시 SwiftUI Apple Watch 앱 충돌 (Series 3 만 해당)

분류에서Dev

릴리스 빌드시 SwiftUI Apple Watch 앱 충돌 (Series 3 만 해당)

분류에서Dev

Apple Watch의 볼륨 조절

분류에서Dev

Apple Watch를 사용한 iAd

분류에서Dev

R Shiny DT 행 선택 및 행 편집 충돌

분류에서Dev

SandboxViolation deny (1) 네트워크 아웃 바운드로 인해 Apple Watch 장치가 충돌 함

분류에서Dev

앱 충돌 후 Apple 시작

분류에서Dev

Swift Apple Pay 충돌; PKPaymentAuthorizationViewController = nil

분류에서Dev

JavaCC 문법에서 선택 충돌의 원인 찾기

분류에서Dev

Apple watch standup detection

분류에서Dev

Apple Watch NFC API

분류에서Dev

Apple Watch의 오디오 녹음 기능

분류에서Dev

Battleship의 함선 충돌 기능 (Javascript)

분류에서Dev

Qt 충돌 선택 상자

분류에서Dev

JavaCC 선택 충돌 경고

분류에서Dev

JavaCC 선택 충돌 경고

분류에서Dev

onPauseState의 충돌

분류에서Dev

CSS의 충돌

분류에서Dev

PPSSignatureView의 충돌

분류에서Dev

ArcRotateCamera의 충돌

분류에서Dev

두 연산자의 이상한 충돌 <<

분류에서Dev

충돌 파일의 충돌 영역에서만 "우리"를 선택적으로 "git checkout --ours"수행 할 수 있습니까?

분류에서Dev

충돌없이 MySQL에서 몇 개의 행을 선택하고 업데이트합니다.

분류에서Dev

순수한 HTML에서 TABLE과 충돌하는 DIV

Related 관련 기사

뜨겁다태그

보관