[英]Iphone Objective-C textfield property autocorrectionType and autocapitalizationType not work simultaneous
[英]Properties / Property: getter doesn't work! Objective-C iPhone
在我的程序中,我做了一個財產:
@property (nonatomic, retain) IBOutlet UIImageView *block;
@synthesize block;
--
現在,如果我這樣做:
NSLog(@"BLOCK = %i", block.center.y);
它只是說:BLOCK = 0
但是我的塊UIImageView對象從不在y = 0上!
請幫忙!
CGPoint.y
是CGFloat
,因此您需要使用%f
來打印出來。
屬性和實例變量是不同的東西。 屬性表示類公開的狀態,而實例變量是實現類狀態的一種方式。
當您編寫block.center.y
您正在訪問名為block
的實例變量 ,而不是調用屬性getter。 要調用屬性getter,必須始終使用點或消息語法,例如:
CGFloat centerY;
centerY = self.block.center.y; // sends -block getter to self
centerY = [self block].center.y; // sends -block getter to self
這是所有不同的示例: isEnabled_
是實例變量, enabled
是屬性, -isEnabled
是由屬性調用的getter方法:
@interface View : NSObject {
@private
BOOL isEnabled_;
}
@property (getter=isEnabled) BOOL enabled;
@end
@implementation View
@synthesize enabled = isEnabled_;
@end
getter=isEnabled
屬性告訴編譯器在獲取enabled
屬性時生成-isEnabled
消息。 @synthesize
將enabled
屬性定義為由實例變量isEnabled_
。
因此,您可以通過以下方式訪問屬性:
BOOL shouldDrawView;
shouldDrawView = someView.enabled; // sends -isEnabled to someView
shouldDrawView = [someView isEnabled]; // also sends -isEnabled to someView
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.