Ios MonoTouch UIWebView.LoadHtmlString在设备上随机失败
我在表的单元格中有Ios MonoTouch UIWebView.LoadHtmlString在设备上随机失败,ios,uiwebview,xamarin.ios,Ios,Uiwebview,Xamarin.ios,我在表的单元格中有UIWebView。我正在调用UIWebView.LoadHtmlString,它在simluator中工作正常,但在具有以下stacktrace的设备上随机崩溃 at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 at EP.TapTeam
UIWebView
。我正在调用UIWebView.LoadHtmlString
,它在simluator中工作正常,但在具有以下stacktrace的设备上随机崩溃
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at EP.TapTeam.Application.Main (string[]) [0x00000] in /projects/tapteam/trunk/iOS/EP.TapTeam.UI/Main.cs:17
at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
Native stacktrace:
Thread started:
0 TapTeam 0x01eb1d79 mono_handle_native_sigsegv + 244
1 TapTeam 0x01e9e429 mono_sigsegv_signal_handler + 172
2 libsystem_c.dylib 0x3669472f _sigtramp + 42
3 UIKit 0x32e452e9 -[UIWebView webView:didCommitLoadForFrame:] + 48
4 UIKit 0x32e445a7 -[UIWebViewWebViewDelegate webView:didCommitLoadForFrame:] + 22
5 CoreFoundation 0x3310d7a4 __invoking___ + 68
6 CoreFoundation 0x3308543d -[NSInvocation invoke] + 108
7 CoreFoundation 0x330850d9 -[NSInvocation invokeWithTarget:] + 36
8 WebKit 0x3328f7bd -[_WebSafeForwarder forwardInvocation:] + 408
9 CoreFoundation 0x3310d68d ___forwarding___ + 576
10 CoreFoundation 0x33084180 _CF_forwarding_prep_0 + 48
11 CoreFoundation 0x3310d7a4 __invoking___ + 68
12 CoreFoundation 0x3308543d -[NSInvocation invoke] + 108
13 WebCore 0x3210ec3d _ZL11SendMessageP12NSInvocation + 16
14 WebCore 0x321b1adf _ZL20HandleDelegateSourcePv + 66
15 CoreFoundation 0x330e1a79 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
16 CoreFoundation 0x330e375f __CFRunLoopDoSources0 + 382
17 CoreFoundation 0x330e44eb __CFRunLoopRun + 230
18 CoreFoundation 0x33074ec3 CFRunLoopRunSpecific + 230
19 CoreFoundation 0x33074dcb CFRunLoopRunInMode + 58
20 GraphicsServices 0x35f3f41f GSEventRunModal + 114
21 GraphicsServices 0x35f3f4cb GSEventRun + 62
22 UIKit 0x32c91d69 -[UIApplication _run] + 404
23 UIKit 0x32c8f807 UIApplicationMain + 670
24 TapTeam 0x000fe5b8 wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 240
25 TapTeam 0x01de3568 EP_TapTeam_Application_Main_string__ + 152
26 TapTeam 0x003f3b74 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
27 TapTeam 0x01e9fc07 mono_jit_runtime_invoke + 1054
28 TapTeam 0x01f1a993 mono_runtime_invoke + 90
29 TapTeam 0x01f1d7eb mono_runtime_exec_main + 306
30 TapTeam 0x01f1da3f mono_runtime_run_main + 482
31 TapTeam 0x01ea472b mono_jit_exec + 94
32 TapTeam 0x01f70b84 main + 2224
33 TapTeam 0x00018fc0 start + 40
我想知道有没有真正的解决办法
更新,我正在使用的代码:
public class OverviewControllerTableSource: UITableViewSource
{
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.DequeueReusableCell(_cellIdentifier) as OverviewCell_text;
if (cell == null)
{
cell = new OverviewCell_text(_cellIdentifier);
}
return cell.Bind(_tableItems[indexPath.Section].Items[indexPath.Row]);
}
}
和细胞
public partial class OverviewCell_text : UITableViewCell
{
public OverviewCell_text (NSString cellId) : base(UITableViewCellStyle.Default, cellId)
{
NSBundle.MainBundle.LoadNib("OverviewCell_text", this, null);
contentWebView.WeakDelegate = new UIWebViewDelegate();
contentWebView.UserInteractionEnabled = false;
contentWebView.Layer.CornerRadius = 5f;
cellText.ScrollEnabled = false;
contentWebView.BackgroundColor = UIColor.Clear;
}
public UITableViewCell Bind(string someInfo)
{
// TODO next string without timer randomly crashes on device.
if(someInfo != null)
{
NSTimer.CreateScheduledTimer(1f, () => {
contentWebView.LoadHtmlString(someInfo, null);
});
}
return cell;
}
}
我们需要查看一些代码来真正帮助您,但是,由于您的解决方案会增加延迟,您应该在当前请求完成之前检查您是否没有重新进入
UIWebView
内部
我要知道,
UIWebView
是,您额外的延迟使请求更有可能(但不安全)完成。出于垃圾收集的目的,将UIWebView作为ViewController类的成员(而不是内联变量)。我使用Nib加载单元格,因此UIWebView是该类的成员。作为建议,像这样将web视图直接放在tableview中通常是不好的做法。我猜您遇到了poupou提到的某种垃圾收集或重入问题。我不知道您的代码如何处理重入问题,即拥有多个UIWebView
(如每个单元格一个)实例不是解决方案。引用(来自与我所链接的问题相关的web博客)“如果您曾经尝试将多个UIWebView对象放在屏幕上,并将文档同时加载到所有对象中,您可能会偶然发现iPhone SDK的一个未记录的限制:UIWebView上的loadRequest方法不会重新进入”,Poupou,感谢您的帮助。我不确定重入问题是否是原因,但在我摆脱Nib并开始以编程方式创建UIWebView后,崩溃就消失了。
public partial class OverviewCell_text : UITableViewCell
{
public OverviewCell_text (NSString cellId) : base(UITableViewCellStyle.Default, cellId)
{
NSBundle.MainBundle.LoadNib("OverviewCell_text", this, null);
contentWebView.WeakDelegate = new UIWebViewDelegate();
contentWebView.UserInteractionEnabled = false;
contentWebView.Layer.CornerRadius = 5f;
cellText.ScrollEnabled = false;
contentWebView.BackgroundColor = UIColor.Clear;
}
public UITableViewCell Bind(string someInfo)
{
// TODO next string without timer randomly crashes on device.
if(someInfo != null)
{
NSTimer.CreateScheduledTimer(1f, () => {
contentWebView.LoadHtmlString(someInfo, null);
});
}
return cell;
}
}