1

据我在xamarin中声明视图控制器中的全局变量是非常重要的,否则当涉及到绑定和所有涉及的时候它可以被垃圾收集。xamarin.ios中的内存管理问题

同样对于通知,我们必须有一个nsobject类型的全局引用,并在我们不需要nsnotification时删除nsobject。

有没有实际的可用文档,使原生的iOS开发者感到沮丧xamarin.ios

暗示一些东西像这将是任何iOS开发者谁成为xamarin.ios开发者的好帮手

回答

0

在每个ViewControllers中输入以下代码:

public override void ViewDidDisappear (bool animated) 
{ 
    //Executed when we navigate to other view, moving this ViewController in Navigation stack 

    //1. UnSubscribe All Events Here (Note: These must be SubScribed back in ViewWillAppear) 
    btnLogin.TouchupInside -= OnLoginClicked 
    //2. Remove Any TapGuestures (Note: These must be added back in ViewWillAppear) 
    if (singleTapGuesture != null) 
    { 
     scrollView.RemoveGestureRecognizer(singleTapGuesture); 
     singleTapGuesture.Dispose(); 
     singleTapGuesture = null; 
    } 
    //3. Remove any NSNotifications (Note: These must be added back in ViewWillAppear) 
    //4. Clear anything here, which again initializes in ViewWillAppear 


    if (ParentViewController == null) { 
     //This section will be executed when ViewController is Removed From Stack 
     //1. Clear everything here 
     //2. Clear all Lists or other such objects 
     //3. Call Following Method which will clear all UI Components 
     ReleaseDesignerOutlets(); 
    } 
    base.ViewDidDisappear (animated); 
} 

当ViewController被导航或从堆栈中移除时,这将清除所有不需要的对象。

对于UITableViews,请使用WeakDataSource & WeakDelegate。

可以有很多更基于以下链接:

Ref 1

Ref 2