從IBAction取得UIButton的Title
發表人:
Seachaos
積分: 2432
積分: 2432
以下是從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]
[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]