» 首頁 » 討論區 » iOS程式討論 »從IBAction取得UIButton的Title

從IBAction取得UIButton的Title

發表人: Seachaos
積分: 2432
發表時間: 2011-09-22 23:52:47
以下是從IBAction的 sender來取得 UIButton的Title 的範例
[sea:javaCode]
- (IBAction)btnClick:(id)sender{

// 檢查 sender 是否為UIButton
if (![sender isKindOfClass:[UIButton class]]){
NSLog(@"Not a button");
return;
}

// 取得 UIButton 的 Title
NSString *title = [(UIButton *)sender currentTitle];
NSLog(@"Title: %@", title);

}
[/sea]