Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIViewController未通过ARC和导航控制器实现_Ios_Objective C_Uiviewcontroller_Uinavigationcontroller_Automatic Ref Counting - Fatal编程技术网

Ios UIViewController未通过ARC和导航控制器实现

Ios UIViewController未通过ARC和导航控制器实现,ios,objective-c,uiviewcontroller,uinavigationcontroller,automatic-ref-counting,Ios,Objective C,Uiviewcontroller,Uinavigationcontroller,Automatic Ref Counting,我有一个导航控制器,它加载UITableviewcontroller(DOArticleListViewController): 当我点击DOArticleListViewController中的“后退”按钮时,视图不会被释放(无dealloc/viewDidUnload),并且每次来回时内存使用量都会增加 原因可能是什么,或者我如何强制释放它? 我可能和“NSFetchedResultsController”有关,因为我最近才搬到ARC TableViewController的声明是: @in

我有一个导航控制器,它加载UITableviewcontroller(DOArticleListViewController):

当我点击DOArticleListViewController中的“后退”按钮时,视图不会被释放(无dealloc/viewDidUnload),并且每次来回时内存使用量都会增加

原因可能是什么,或者我如何强制释放它? 我可能和“NSFetchedResultsController”有关,因为我最近才搬到ARC

TableViewController的声明是:

@interface DOPrototypeListViewController : DOPrototypeViewController <NSFetchedResultsControllerDelegate, UITableViewDelegate> {

    IBOutlet UITableView * _tableView;

    int _cellHeight;

@protected
    NSFetchedResultsController* _objects;   
    NSString* _cellIdentifier;

    bool _commonId;
    int _sectionItemsSkipped;
}

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSFetchedResultsController* objects;

- (NSIndexPath*)calculateObjectIndexPath:(NSIndexPath*) indexPath;
- (NSIndexPath*)calculateTableIndexPath:(NSIndexPath*) indexPath;

@end

在ARC之前,我会这样做,但现在我没有在视图控制器从视图堆栈中移除时调用的函数(并且可以移除,但这只是在返回到某个级别时,而不是在返回到详细视图控制器时调用)。

我想您可以为

DOArticleListViewController* listView

这样,你可以重用你的VC

编辑:

回应有关“后退”按钮的评论

// Set the left button for menu
UIImage *menuImage = [UIImage imageNamed:@"back_image"];

//create the button and assign the image
UIButton *menuButton = [UIButton buttonWithType:UIButtonTypeCustom];
[menuButton setImage:menuImage forState:UIControlStateNormal];

[menuButton addTarget:self action:@selector(backButtonEvent:) forControlEvents:UIControlEventTouchUpInside];

//create a UIBarButtonItem with the button as a custom view
UIBarButtonItem *menuBarItem = [[UIBarButtonItem alloc] initWithCustomView:menuButton];
self.navigationItem.leftBarButtonItem = menuBarItem;
然后,在BackButtoneEvent方法上,您可以添加所有清理操作,然后为当前VC生成pop:

-(IBAction)backButtonPressed:(id)sender{
    //Clear here
    [self.navigationController popViewControllerAnimated:YES];
}

可能需要虚弱,是的。我认为你在那里遇到了一个保留周期的问题。使用仪器和分配工具来发现您是否在
DOArticleListViewController
中注册任何观察者或运行任何计时器?如果我使NSFetchedResultsController变弱,我将丢失detailviewcontroller的对象。除了类是tableView的委托之外,我没有任何观察者。我可以将对象设置为“nil”,如果有一个函数只有在视图控制器通过管道传输时才调用(例如,当选择一行时,则ViewDidEnglish将不起作用),则只需检查仪器即可。每个新实例都是活动的,但如何检查原因。他们有1的ReCal计数,但是我如何检查这是从哪里来的呢?我认为这是一个更基本的问题,看看EddithEngult是个好主意,我会考虑一些课程。但是,在其他一些视图(菜单)中,我有时会有子菜单,因此确实需要特定的实例,但这无助于确定是什么导致视图无法发布。是的,你说得对。你可以做的另一件事是用你自己的“后退”方法覆盖后退按钮,并在为VC制作pop之前清除所有的强引用、观察者和委托。是否有一个特定的内置函数,或者只是创建你自己的按钮和动作?谢谢,我可能也会使用它。然而,目前我已经在中实现了第二个答案
-(DOArticleListViewController*)listView{
    if (!_listView){
        _list = [[[self navigationController] storyboard] instantiateViewControllerWithIdentifier:@"DOArticleListViewController"];
    }
    return _listView;
}
// Set the left button for menu
UIImage *menuImage = [UIImage imageNamed:@"back_image"];

//create the button and assign the image
UIButton *menuButton = [UIButton buttonWithType:UIButtonTypeCustom];
[menuButton setImage:menuImage forState:UIControlStateNormal];

[menuButton addTarget:self action:@selector(backButtonEvent:) forControlEvents:UIControlEventTouchUpInside];

//create a UIBarButtonItem with the button as a custom view
UIBarButtonItem *menuBarItem = [[UIBarButtonItem alloc] initWithCustomView:menuButton];
self.navigationItem.leftBarButtonItem = menuBarItem;
-(IBAction)backButtonPressed:(id)sender{
    //Clear here
    [self.navigationController popViewControllerAnimated:YES];
}