【问题标题】:ARC conversion of TPMultiLayoutViewController; Implicit conversion of an Objective-C pointer to 'const void *' is disallowed with ARCTPMultiLayoutViewController的ARC转换; ARC 不允许将 Objective-C 指针隐式转换为“const void *”
【发布时间】:2012-01-26 11:45:03
【问题描述】:

我正在尝试在使用 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];
        }
    }
}

【问题讨论】:

  • 方法中的第一个[table setObject:[self attributesForView:view] forKey:[NSValue valueWithPointer:associatedView]];
  • 这部分特别是[NSValue valueWithPointer:associatedView]
  • 为什么不把关联的View直接放到NSDictionary中呢?
  • 一般(__bridge void *) 但是我不明白为什么你会在那里得到那个错误。 setObject:forKey 应该采取id
  • 你可以使用视图对象作为键吗?

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


【解决方案1】:

您因此收到错误消息:

[NSValue valueWithPointer:associatedView]

因为valueWithPointer: 需要const char *。您可以按照@ user1139069 的建议解决此问题:

[NSValue valueWithPointer:(__bridge void *)associatedView]

【讨论】:

    【解决方案2】:

    如果您使用[NSValue valueWithNonretainedObject:] 而不是[NSValue valueWithPointer:] 会怎样?

    【讨论】:

      猜你喜欢
      • 2011-10-15
      • 2012-01-04
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多