开发者

Iphone-MultiButton-Events

开发者 https://www.devze.com 2023-03-01 18:09 出处:网络
I Have One Xib File IN Which There Are About 50 Buttons.. And All Are Have Same Functionality... Like On Click I Change Background Image (Select)And...

I Have One Xib File IN Which There Are About 50 Buttons..

And All Are Have Same Functionality... Like On Click I Change Background Image (Select)And... And Second Time Click Also Change Background Packet (Deselect) ..

开发者_开发技巧If I Make All Button Own Events .. Then It's Ok..

But I Want To Create Single Function Which Handles All Buttons...

I Try It.. I Can't Get Specific Typecasting

Coding

.h File

-(IBAction) BtnShpPress:(id)sender;

.m File

-(IBAction) BtnShpPress:(id)sender
{
    UIButton *BtnShp= (UIButton * ) sender;
    NSString *Str = BtnShp.name; //Here I Ca't Get Specific Object
}

And I Apply This Event On 4 Buttons - TouchDown Events


-(IBAction) BtnShpPress:(id)sender
{
    UIButton *BtnShp= (UIButton * ) sender;
    NSString *Str = [BtnShp currentTitle]; //This gives title of button
}

You can also set tag and access them too using button.tag


use this to get title -

NSString *Str = [[BtnShp titleLabel] text];
0

精彩评论

暂无评论...
验证码 换一张
取 消