按钮图像更改按钮单击,然后转到下一个子视图

时间:2011-03-09 13:24:18

标签: iphone uibutton

这是我的第二个问题。

我有按钮。当我按下它时,我想进入“下一个屏幕”。另一个SubView。但是当按下按钮时我想改变它的图像。我写了一些代码但是当我按下按钮时,View打开但图像按钮没有改变。当我回到第一个视图时,其他按钮图像被更改。请帮忙。

- (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]; //show icon with new image for second
    [lista removeFromSuperview]; //then close lista view
    [self addSubview:kotek]; //and then open kotek view
}

1 个答案:

答案 0 :(得分:0)

您正在更改选择时的按钮状态。您也正在将UI线程置于睡眠状态。当您调用线程休眠时,您将睡眠负责绘制用户界面元素的线程。确保您在按钮上设置了正确的状态,并安排计时器翻到下一页。

[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

相关问题