Button Image Change button click and then go to next Subview
this is my second question here.
I have button. When I press it I want to go to "next screen". Another SubView. But also when button is pressed I would like to change its image. I wrote some code but when I press button next View is open but image button doesn't change. when I come back to first view by some other button image is changed. please help.
- (IBAction)kotlista:(id)sender{
[kotzlisty setImage:[UIImage imageNamed:@"pies.png"] forState:UIControlStateSelected]; //current image is kot.png, I want to change it for pies.png
[NSThread sleepForTimeInterval:1.0]; //sh开发者_开发知识库ow icon with new image for second
[lista removeFromSuperview]; //then close lista view
[self addSubview:kotek]; //and then open kotek view
}
you are changing the button state for when it is selected. Also you are putting the UI thread to sleep. When you call thread sleep you sleep the thread that is in charge of drawing the user interface elements. Make sure you are setting the correct state on the button and schedule a timer to flip to the next page.
[NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(nextPage:)
userInfo:nil
repeats:NO];
//timer funciton
-(void) nextPage:(NSTimer*)t
{
//bla
}
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html
精彩评论