developers.
我是新的单点触控开发人员。
我的应用程序在此代码块上运行良好,但突然关闭并出现此错误。我哪里会做错事?我该如何解决?谢谢。
NewsElement.Tapped+= delegate(object sender, EventArgs e)
{
try
{
News news=_news.Find(x => x.Title== _section.Elements[NewsElement._indexPath.Row].Caption.ToString());
using(NewsDetailViewController nDVC=new NewsDetailViewController(news,_newsEnum))
{
this.NavigationController.NavigationBar.BarTintColor = ExtensionMethods.ToUIColor("4BC1D2");
this.NavigationController.NavigationBar.TintColor=UIColor.White;
this.NavigationController.PushViewController (nDVC, true);
}
}
catch
{
}
};
错误是:
mono-rt: Stacktrace:
mono-rt: at <unknown> <0xffffffff>
mono-rt: at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (intptr,intptr) <IL 0x00026, 0xffffffff>
mono-rt: at MonoTouch.UIKit.UIViewController.get_NavigationController () [0x00030] in /Developer/MonoTouch/Source/monotouch/src/build/compat/UIKit/UIViewController.g.cs:1595
mono-rt: at HaberOku.MainViewController.<LoadView>m__A (object,System.EventArgs) [0x00029] in /Users/muhammetsahin/Projects/HaberOku/HaberOku/DialogViewControllers/MainViewController.cs:89
mono-rt: at (wrapper delegate-invoke) System.EventHandler`1.invoke_void__this___object_TEventArgs (object,TEventArgs) <IL 0x00027, 0x00087>
mono-rt: at (wrapper delegate-invoke) System.EventHandler`1.invoke_void__this___object_TEventArgs (object,TEventArgs) <IL 0x00059, 0xffffffff>
mono-rt: at HaberOku.NewsElement.Selected (MonoTouch.Dialog.DialogViewController,MonoTouch.UIKit.UITableView,MonoTouch.Foundation.NSIndexPath) [0x00029] in /Users/muhammetsahin/Projects/HaberOku/HaberOku/Elements/NewsElement.cs:61
mono-rt: at MonoTouch.Dialog.DialogViewController.Selected (MonoTouch.Foundation.NSIndexPath) [0x00033] in /Users/muhammetsahin/Projects/HaberOku/HaberOku/MonoTouchDialog/DialogViewController.cs:522
mono-rt: at MonoTouch.Dialog.DialogViewController/Source.RowSelected (MonoTouch.UIKit.UITableView,MonoTouch.Foundation.NSIndexPath) [0x00021] in /Users/muhammetsahin/Projects/HaberOku/HaberOku/MonoTouchDialog/DialogViewController.cs:368
mono-rt: at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object_object (object,intptr,intptr,intptr) <IL 0x0005a, 0xffffffff>
mono-rt: at <unknown> <0xffffffff>
mono-rt: at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
mono-rt: at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
mono-rt: at HaberOku.Application.Main (string[]) [0x00009] in /Users/muhammetsahin/Projects/HaberOku/HaberOku/Main.cs:17
mono-rt: at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
mono-rt:
Native stacktrace:
mono-rt:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
这是一个
非常奇怪的模式。 一旦块完成,它将释放 nDVC,即使您刚刚将 nDVC 推送到导航堆栈并且仍在使用它。 尝试删除 using(),以便 nDVC 不会被过早释放。
using(NewsDetailViewController nDVC=new NewsDetailViewController(news,_newsEnum))
{
this.NavigationController.NavigationBar.BarTintColor = ExtensionMethods.ToUIColor("4BC1D2");
this.NavigationController.NavigationBar.TintColor=UIColor.White;
this.NavigationController.PushViewController (nDVC, true);
}
当我引用在执行委托时不再处于活动状态的对象时,我也会遇到这种错误。
因此,也许您可以尝试确保您正在调用的对象仍然可用/未被垃圾回收。尝试发送它们或执行空检查。