gpt4 book ai didi

ios - 更改 UIImageView 的位置 - 为什么我得到 "request for member error"

转载 作者:行者123 更新时间:2023-11-29 13:15:17 24 4
gpt4 key购买 nike

Request for member 'bunny' in something not a structure or union

我为什么会收到这个错误?我的行看起来像这样:

[self.bunny setFrame:CGRectMake(100, 100, 100, 100)];

声明的属性为:

@property (nonatomic, strong) UIImageView *bunny;

我初始化它:

self.bunny = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 50, 50)];
self.bunny.image = [UIImage imageNamed:@"bunny.png"];

但是所有的赋值行都因该错误而出错。我做错了什么?

最佳答案

我没有发现您发布的代码有任何问题。确保您没有无意中将该属性声明为 UIImage 而不是 UIImageView。如果您还没有这样做,请发布 VC 中的所有代码。

对于其他人的信息,在 Xcode 4.4 及更高版本中,属性会自动合成为 property = _property

好的。从你发给我的项目来看,有两个问题:

  1. 如果您不使用 ARC(您发送给我的项目不是),则需要使用 retain 指令而不是 strong 来声明该属性

  2. 你已经将该类实例化为一个类别,你不能这样做并且有一个私有(private)类变量。要么删除该类别名称,要么声明

@property (nonatomic, retain) UIImageView *bunny;

改为在头文件中。

和实现文件:

#import "SlidingTableViewCell.h"
#import "CellBack.h"
#import "CellFront.h"


@interface SlidingTableViewCell (ShitBalst)
-(void)springBack;
-(void)toggleTableScrolling:(BOOL)canScroll;
@end


@implementation SlidingTableViewCell
@synthesize bunny;

#define kDragDist 80.0

顺便说一句 - 这是我更新的项目: https://dl.dropboxusercontent.com/u/3660978/TableViewCellSlider.zip

关于ios - 更改 UIImageView 的位置 - 为什么我得到 "request for member error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15982556/

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