2009-05-22 67 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