开发者

Switching orientations causes UIButton redraw

Switching orientations causes UIButton redraw

I'm switching to landscape and it redraws the UIButton. here is the button code.

plusButton = [[[UIButton alloc] initWithFrame:CGRectMake(bounds.size.width - 60.0f,       28.0f, 45.0f,90.0f)] autorelease ];
[plusButton开发者_JS百科 setImage:TTIMAGE(@"bundle://morebutton.png")
            forState:UIControlStateNormal];
[plusButton showsTouchWhenHighlighted];
[plusButton addTarget:self action:@selector(plusButtonDidPress:)
 forControlEvents:UIControlEventTouchUpInside];
[self addSubview:plusButton];

This is a TTMessageitemcell (THREE20)

Any suggestions would be appreciated. thanks.


Is this being called in drawRect or something similar? It looks as if it's creating a new instance of the button each time a drawing method is called. Try making plus button an instance variable of your cell and initialise it in the init method. Then you can set frame and other properties in the drawing method while only using one instance of the button. You can then release the button in dealloc.

tl;dr: looks as if you're adding multiple instances of the button in a drawing method eg. drawRect: or layoutSubviews.

Tim


plusButton = [[[UIButton alloc] initWithFrame:CGRectMake(bounds.size.width - 60.0f,       28.0f, 45.0f,90.0f)] autorelease ];

[plusButton setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin];


[plusButton setImage:TTIMAGE(@"bundle://morebutton.png")
            forState:UIControlStateNormal];
[plusButton showsTouchWhenHighlighted];
[plusButton addTarget:self action:@selector(plusButtonDidPress:)
     forControlEvents:UIControlEventTouchUpInside];
[self addSubview:plusButton];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜