gpt4 book ai didi

xcode4.2 - 添加 subview 时发送到实例的无法识别的选择器

转载 作者:行者123 更新时间:2023-12-01 12:37:07 24 4
gpt4 key购买 nike

我在运行我的应用程序时收到此线程。

2012-07-10 15:44:39.668 DSSAmple[447:f803] -[cell superview]: unrecognized selector sent       to instance 0x68b4080
2012-07-10 15:44:39.671 DSSAmple[447:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[cell superview]: unrecognized selector sent to instance 0x68b4080'

'cell' 称为我的子类。

在 cell.h 我有

@interface cell : UIViewController
{
UIImage *MyImage;
int row;
int column;
CGRect frame;
}
@property(retain,nonatomic)UIImage *MyImage;
@property(assign,nonatomic)int row;
@property(assign,nonatomic)CGRect frame;
@property(assign,nonatomic)int column;
@end

在我的调用类中,我有 SIAViewcontroller.h

#import <UIKit/UIKit.h>
#import "cell.h"
@interface SIAViewController : UIViewController
-(void)PanelLoading;
@end

在实现中 SIAViewController.m

-(void)PanelLoading
{
UIImage *myImage=[UIImage imageNamed:@"s.jpg"];
int x=20,y=50,r=1,c=1;
for (int i=1; i<=8; i++)
{
for (int j=1; j<=8; j++)

{
cell *tank=[[cell alloc]init];
tank.column=c;
tank.row=r;
tank.frame=CGRectMake(x, y, 35, 35);
tank.MyImage=myImage;
[self.view addSubview:tank];
x+=35;
r++;
}
r=1;
c++;
y+=35;
x=20;
}

}

- (void)viewDidLoad
{
[super viewDidLoad];
[self PanelLoading];
// Do any additional setup after loading the view, typically from a nib.
}

这是什么原因?有人可以帮忙吗?

最佳答案

您的 cell 类应该扩展 UIView 而不是 UIViewController

@interface cell : UIView

UIView 提供了一个 superview 属性,而 UIViewController 没有,触发了“无法识别的选择器”崩溃。

关于xcode4.2 - 添加 subview 时发送到实例的无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11411947/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com