2009-05-22 124 views
-4
-(void)clicketbutton{ 
    UIButton *mybutton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [mybutton setTitle:@"Click here" forState:UIControlStateNormal]; 
    [mybutton addTarget:self action:@selector(displayvalue:)forControlEvents:UIControlEventTouchUpInside]; 
} 

-(void)displayvalue:(id)sender{ 
UIButton *resultebutton= [UIButton buttonWithType:UIButtonTypeCustom]; 

resultebutton=sender;// pls clear here.. my question here , it it possible or not. if possible how ? NSLog(@" The buttontitile is %@ ", [resultebutton.Title] // here also. } 

在上面的代碼中,我創建了一個按鈕並將標題設置爲Click here。當我按下那個按鈕時,我想打印Click here,我的意思是它的標題。爲此,我的代碼在這裏。選擇器關鍵字

回答

1

iid是發件人,它是調用displayvalue方法的控件的指針。您將指針轉換爲整數,並打印整數結果。我不確定你想要完成什麼,但是從按鈕到按鈕的操作方法獲取整數的最快方法是將其存儲在tag屬性中。

如果您更詳細地瞭解您正在處理的內容,我可能會描述在Cocoa應用程序中建模的最佳方法。另外,提示 - 在嘗試弄清楚爲什麼某些東西不能正常工作之前,一定要修正代碼中的任何警告!例如,這個id - > int賦值會讓編譯器抱怨。

+0

hi arc charbonneau ... Thankyou非常..迴應我.. 我提到我的問題很清楚..請幫助我..這是非常迫切的。 非常感謝你一次 – Raju 2009-05-23 05:01:56