English 中文(简体)
ARC下被宣布的物体的寿命如何?
原标题:What is the lifetime of an object declared in a block under ARC?

我对区块和阿法索委员会的理解存在差距,我希望得到一些帮助。 我收到了来自估算完成组的测试器的坠毁报告。 坠毁情况如下:

Exception Type: EXC_BAD_ACCESS (SIGSEGV)

特殊法:KERN_INVALID_ADDRESS at 0xf0000010

这是在下列消化装置内进行的(使用animateWithDuration:completion:)。 我正在利用一个临时变量抽取两个观点控制器:

{
    [current wasMovedOffScreen];
    PlayerViewController *temp = current;
    current = next;
    next = temp;
}

<代码>next = 速度; 是发生坠机的线。 估计时间为0.3秒。

该守则是在作为其他两个观察控制器的集装箱的视力控制器内实施的,该控制器用来模拟通过导航控制器等物体清单的用户,但有些定制意味着导航控制器不适合我。

两名儿童观点控制员被称为“现存”和“赠与”,因为你可以猜测目前的控制人员显示目前的内容,而下一个是在用户通过清单移动时新项目使用的。

如果我改动了栏目,以便<代码>temp在实施时(连同<代码>现和next/code>)宣布坠机停机。 然而,我认为没有必要为根据定义属于当地和临时的某种东西而设一等。

因此,

  • Why is temp apparently released by ARC during this process?
  • What would be the correct way to implement this? Is there some lifetime qualifier I should add to the block implementation?
  • Why could I not reproduce the crash on my own device or in the simulator? Both devices were iPhone 4 running the same version of iOS (5.0.1).
最佳回答

如果你真的坚持下去,因为你只能改变两种观点,那么你实际上就不需要目前/今后的所有工作。 如果你想要的话,你可以保持目前的轨道,但这里的想法是这样。

如果有:

@property (nonatomic, strong) UIViewController *controller1;
@property (nonatomic, strong) UIViewController *controller2;
@property (nonatomic, weak) UIViewController *currentController;

之后,你可以采用一种方法:

- (id)swapControllers {
    // use the current controller to figure out what the next controller is, so
    // you don t have to do the two way swap. do in the completion, if you like.    
    UIViewController *nextController = ([self.currentController isEqual:self.controller1]) ? self.controller1 : self.controller2;
    [UIView animateWithDuration:.25
                     animations:^{
                         // TODO: some animations on currentController and nextController
                     } completion:^(BOOL finished) {
                         [self.currentController wasMovedOffScreen];
                         self.currentController = nextController;
                     }];
}

关于您的原始问题,美国难民事务委员会知道如何妥善处理块块块——如果你使用该块,我可能会问,你是否被遗忘复制在其他地方宣布的一块块,然后储存起来,然后作为完成手通过。 既然情况并非如此,而且由于你没有能够重新提出。 我猜测,你可能会坐着一个塔克,但阿农研中心的一些灯塔迟释放。 如果是这样的话,你可以尝试利用最后稳定的释放,看看你是否取得更好的结果。

问题回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...