-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,我的意思是它的标题。为此,我的代码在这里。

4

1 回答 1

1

iid 是发送者,一个指向调用你的 displayvalue 方法的控件的指针。您将指针转换为整数,并打印整数结果。我不确定您要完成什么,但是从按钮获取整数到按钮操作方法的最快方法是将其存储在tag属性中。

如果你更详细地了解你正在做什么,我可能能够描述在 Cocoa 应用程序中建模的最佳方法。另外,一个提示——在试图找出为什么某些东西不起作用之前,一定要修复代码中的任何警告!例如,那个 id -> int 赋值会让编译器抱怨。

于 2009-05-22T03:47:58.927 回答