TPMultiLayoutViewController的ARC转换;使用ARC不允许将Objective-C指针隐式转换为'const void *'

时间:2012-01-26 11:45:04

标签: objective-c ios automatic-ref-counting

我正在尝试在使用ARC的项目中使用TPMultiLayoutViewController,但是遇到了以下错误: -

  

ARC

不允许将Objective-C指针隐式转换为'const void *'

我真的不确定如何解决这个问题;它需要明确转换吗?我该怎么做?

- (void)addAttributesForSubviewHierarchy:(UIView*)view associatedWithSubviewHierarchy:(UIView*)associatedView toTable:(NSMutableDictionary*)table {
    [table setObject:[self attributesForView:view] forKey:[NSValue valueWithPointer:associatedView]];

    if ( ![self shouldDescendIntoSubviewsOfView:view] ) return;

    for ( UIView *subview in view.subviews ) {
        UIView *associatedSubView = (view == associatedView ? subview : [self findAssociatedViewForView:subview amongViews:associatedView.subviews]);
        if ( associatedSubView ) {
            [self addAttributesForSubviewHierarchy:subview associatedWithSubviewHierarchy:associatedSubView toTable:table];
        }
    }
}

2 个答案:

答案 0 :(得分:5)

因为这个原因你得到了错误:

[NSValue valueWithPointer:associatedView]

由于valueWithPointer:需要const char *。您可以通过执行@ user1139069建议:

来解决此问题
[NSValue valueWithPointer:(__bridge void *)associatedView]

答案 1 :(得分:0)

如果您使用[NSValue valueWithNonretainedObject:]代替[NSValue valueWithPointer:]怎么办?