ios - UITableView custom accessory button image disappears when tapped -
i have uitableview custom accessory button created this:
in cellforrowatindexpath
method following:
... uibutton *myaccessorybutton =[[[uibutton alloc] init] autorelease]; myaccessorybutton =[self makeaccessorybutton: @"arrow2.png"]; [cell setaccessoryview:myaccessorybutton]; return cell;
and function makeaccessorybutton
defined follows:
- (uibutton *) makeaccessorybutton: (nsstring *) imagename { uibutton *myaccessorybutton = [[uibutton buttonwithtype:uibuttontypecustom] autorelease]; cgrect frame = cgrectmake(0, 0, 24, 24); myaccessorybutton.frame = frame; [myaccessorybutton setbackgroundcolor:[uicolor clearcolor]]; [myaccessorybutton setimage:[uiimage imagenamed:imagename] forstate: uicontrolstatenormal]; [myaccessorybutton addtarget: self action: @selector(accessorybuttontapped:withevent:) forcontrolevents: uicontroleventtouchupinside]; //myaccessorybutton.userinteractionenabled = yes; return ( myaccessorybutton ); }
and function defined follows:
- (void) accessorybuttontapped: (uicontrol *) button withevent: (uievent *) event { nslog(@"testing ..."); }
now problem is: when tap on button, image disappear when row highlighted, tried both states uicontrolstatenormal
, uicontrolstatehighlighted
button problem still exists, mentioned. if tap button if table view row not selected (or highlighted) there not problem button image (it not disappear). how can fix problem?
add image uicontrolstatehighlighted
or uicontrolstateselected
in custom accessory button.
[myaccessorybutton setimage:[uiimage imagenamed:imagename] forstate:uicontrolstatehighlighted];
Comments
Post a Comment