【问题标题】:Why am I am getting the warning "Multiple methods named 'center' found"为什么我收到警告“找到多个名为 'center' 的方法”
【发布时间】:2012-06-20 23:52:20
【问题描述】:

只有在我导入助手类 (#import "JLHelper.h") 时才会收到此警告。

出现警告的示例...

[[subViews objectAtIndex:i] center].y+translation.y)];

我知道它告诉我编译器看到多个名为 center 的方法,但 center 是在 CLRegion.h 的框架中声明的。

为什么在这种情况下编译器会看到不止一种方法?是否存在需要关注的问题,如果是,我该如何追踪和解决。

谢谢,

约翰

问题解决了,感谢 Eric!这是修复后对我的代码进行更广泛的了解

NSArray *subViews = [self subviews];
UIImageView *bottomResizer;
int count = [subViews count];
for (int i =count-1; i>=0; i--) {
    if([[subViews objectAtIndex:i] tag] == 301) {
        bottomResizer = (UIImageView*)[subViews objectAtIndex:i];
        [bottomResizer setCenter:CGPointMake([bottomResizer center].x, [bottomResizer center].y+translation.y)];

    }
}

【问题讨论】:

    标签: iphone xcode ipad compiler-warnings


    【解决方案1】:

    看起来您需要投射对象,以便它知道您的意思是什么中心......

    [((OBJECT_TYPE*)[subViews objectAtIndex:i]) center].y+translation.y)];
    

    OBJECT_TYPE 是一个 CLRegion 对象

    【讨论】:

    • 是的!就是这样。对于任何感兴趣的人,我已将工作代码作为我的问题的附录。谢谢埃里克!
    猜你喜欢
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多