我正在研究是否有可能将我们维护的旧应用移植到Xamarin,以便在我们的iOS和安卓版本之间建立共享的代码库。
不幸的是,我在移植iOS应用程序时遇到了一些问题。我用不同的方法来解决这个问题,让这个应用程序以一个nib文件作为主要的入口点(因为我们现在的应用程序就是这么做的,它很老了)。无论我做什么,它似乎总是崩溃或变黑。
下面是我尝试的一个概要:
发布于 2016-02-04 17:57:17
我在github上深入研究了一些代码示例,并找到了一个适当的解决方案。无论Xamarin在幕后做什么来引导主窗口,似乎都与在Info.plist文件中设置主nib不兼容。例如,AQTapDemo项目通过在AppDelegate中手动加载视图控制器来解决这个问题,而不是依赖于来自Info.plist属性的自动加载。
发布于 2016-02-04 05:31:36
因此,如果查看状态跟踪,就会看到ObjC异常是在试图建立出口连接时抛出的:
0 CoreFoundation 0x008dea14 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0890ce02 objc_exception_throw + 50
2 CoreFoundation 0x008de631 -[NSException raise] + 17
3 Foundation 0x00f371bc -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x00e9183a _NSSetUsingKeyValueSetter + 115
5 Foundation 0x00e917bf -[NSObject(NSKeyValueCoding) setValue:forKey:] + 295
6 Foundation 0x00ec601d -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 384
7 UIKit 0x03639cb4 -[UIRuntimeOutletConnection connect] + 132查看您的.xib,已经定义了一个连接,但是您在C#中没有一个匹配的定义(以及生成的.h),因此注释掉它将允许在运行时对.xib进行解析校正:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MainNib">
<!--
<connections>
<outlet property="view" destination="2" id="RRd-Eg-VrN"/>
</connections>
-->
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="2">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</objects>
</document>除了具有两个属性设置的.xib之外,在UIView中没有任何东西。
发布于 2016-02-04 05:56:54
我相信您的MainNib有组件,这些组件在代码中使用,但缺少与属性的连接。
可能的解决方案:
*右击MainNib文件-> Open With -> Xcode Interface Builder。
Xcode将使用该.xib文件打开。
*选择File's Owner在Placeholders in Document Outline (介于ProjectNavigator和Storyboard画布之间)。
*单击Xcode右侧的连接检查器。
*检查您将从代码中操作的所有视图组件是否与其相应的属性连接。
*修复连接,或在需要时创建属性。
*保存更改并关闭xcode。
*刷新Xamarin项目或重新打开该项目并运行。
希望这能解决坠机问题。
https://stackoverflow.com/questions/35183847
复制相似问题