【问题标题】:How do i fix the warning我如何修复警告
【发布时间】:2012-07-07 08:10:13
【问题描述】:

我的项目中有两个类:SIAViewController.h,以及它的子类cell.h

cell.h我有

@interface cell : UIViewController
@property(nonatomic)CGRect frame;
@property(assign,nonatomic)UIImage *image;
@property(nonatomic)int tag;
@property(nonatomic)bool userInteractionEnabled;
@property(retain,nonatomic)UITapGestureRecognizer *addGestureRecognizer;
@end

SIAViewController.m

int x=20,y=50,t=1;
cell *tank[9][9];
for(int i=1;i<=8;i++)
{
    for(int j=1;j<=8;j++)
    {
        tank[i][j]=[[cell alloc]init];
        tank[i][j].frame=CGRectMake(x, y, 35, 35);
        UIImage *myImage=[UIImage imageNamed:@"s.jpg"];
        [tank[i][j] setImage:myImage];
        tank[i][j].tag=t;
        tank[i][j].userInteractionEnabled=YES;
        UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapDetected:)];
        tank[i][j]. addGestureRecognizer=recognizer;
        [self.view addSubview:tank[i][j]];
        x+=35;
        t++;
    }
    y+=35;
    x=20;
}

在运行项目时,我收到线程不兼容的指针类型,将单元 __strong 发送到 uiview 类型的参数。谁能帮我。我是 xcode 的新手。谢谢

【问题讨论】:

    标签: ios xcode4.2


    【解决方案1】:

    原因是,UIView 是表格视图单元格的超类。这意味着如果某些属性应该是 UITableViewCell,但您传入了一个通用的 UIView 实例,则该 UIView 可能但不一定也是 UITableViewCell。这就是编译器警告您的原因。如果您知道要设置的实例实际上是伪装成 UIView 的 UITableViewCell,则可以放心地忽略此警告,因为 Objective-C 是一种动态语言;类型声明仅用于欺骗编译器;类型匹配发生在运行时。

    【讨论】:

    • 看到我收到线程终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因:'-[cell superview]:无法识别的选择器发送到实例 0x68441d0'
    猜你喜欢
    • 1970-01-01
    • 2019-08-08
    • 2020-11-28
    • 2017-10-25
    • 2017-07-03
    • 2019-12-07
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    相关资源
    最近更新 更多