1

i'm using TMQuiltView, my project has ARC enabled, but TMQuilView does not. In my controller I dequeue the cell by

// ARC
TMQuiltViewCell* quiltCell = [_quiltView dequeueReusableCellWithReuseIdentifier:reuseIdentifier];

but quiltCell is always nil. Inside dequeueReusableCellWithReuseIdentifier: it likes this

// No ARC
- (TMQuiltViewCell *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier {
    TMQuiltViewCell *view = [[self reusableViewsWithReuseIdentifier:identifier] anyObject];
    if (view) {
        [view retain];            
        view.selected = NO;
        [[self reusableViewsWithReuseIdentifier:identifier] removeObject:view];
    }
    return [view autorelease];
}

The view is NOT nil, and alway has retain count is 1 before the autorelease call, but the returned value quiltCell is nil. Is that [view autorelease] releases view before returning? How do i keep reference to the returned object?

UPDATED:

I came up with a workaround by delay autorelease call a bit

[view performSelector:@selector(autorelease) withObject:nil afterDelay:0.01];

It works for me, but I still want to have a prettier solution.

jAckOdE
  • 2,282
  • 7
  • 34
  • 64
  • 2
    I saw that the TMQuiltView was using retain count, but I dismissed that as I gather that's not your code. However, it looks like you're using that information to make judgements about whether or not it's working.. *don't*!. retain count is notoriously unreliable. – James Webster Jul 12 '13 at 07:33
  • all the retaincount code i made to log the retain count to console, it is not TMQuiltView original code. I removed all the loggin code. – jAckOdE Jul 12 '13 at 07:47
  • Did you allocate any "TMQuiltViewCell" in the memory before using "dequeueReusableCellWithReuseIdentifier"? – x4h1d Jul 12 '13 at 08:27
  • no, i check if there is any reusable cell (returned object of `dequeueReusableCellWithReuseIdentifier:`) first, and allocate new `TMQuiltViewCell` only if I get nil. Pretty much the same way we usually do with UITableView – jAckOdE Jul 12 '13 at 08:32
  • `all the retaincount code i made` - Then definitely don't! [Check out this question](http://stackoverflow.com/questions/4636146/when-to-use-retaincount) – James Webster Jul 12 '13 at 08:33
  • thanks, those code is just for testing, it will never appear in my release, and it's not the main point of the question anyway. – jAckOdE Jul 12 '13 at 08:36
  • `retainCount` isn't suitable for testing! It is the main point of the question if you're making deductions from that code. – James Webster Jul 12 '13 at 09:18

0 Answers0