トリガーする特定のメソッドで特定の UIControl にアプローチしたいとしましょう。「sender」を使用してメソッドに UIControl へのポインターを送信できます。しかし、何らかの理由で、送信者のプロパティに直接アクセスできず、setX:forState: メソッドを使用する必要があります。プロパティに直接アクセスしても、エラーや警告は表示されません。それは単に何もしません...
次に例を示します。
h. file...
@interface MYViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIButton *dButton; //connected to a UIButton in IB
-(IBAction)dButtonClick:(UIButton*)sender; //connected to the same UIButton in IB
@end
それから...
m. file...
- (void)viewDidLoad
{
[super viewDidLoad];
self.dButton.titleLabel.textColor = [UIColor greenColor]; //this is working...
}
-(IBAction)dButtonClick:(UIButton*)sender
{
sender.titleLabel.textColor = [UIColor redColor]; //this is not working...
self.dButton.titleLabel.textColor = [UIColor redColor]; //this is also not working...
[sender setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; //only this is working.
//But why?!?!?
}
これらのアイテムがどのように機能するかについていくつかの情報を検索しようとしましたが、その背後にあるロジックを十分に明確に説明するものは見つかりませんでした.
どんな助けでも...まあ...役に立つ...