我正在制作一个非常简单的应用程序。我有一个计时器,当计时器超过5秒时,我想要显示一个图像。如果计时器不超过5秒,则图像应保持隐藏状态。问题是,我的图像出现在我的main.storyboard
上,一旦定时器超过5秒,我似乎无法使其消失。任何帮助,将不胜感激!这里是我的代码:在Xcode中隐藏和显示图像
ViewController.h:
#import <UIKit/UIKit.h>
int CountNumber;
@interface ViewController : UIViewController
{
IBOutlet UILabel *TimerDisplay;
IBOutlet UIImageView *Images;
NSTimer *Timer;
}
-(void)TimerCount;
-(IBAction)Start:(id)sender;
-(IBAction)Stop:(id)sender;
-(IBAction)Restart:(id)sender;
@property (strong, nonatomic) IBOutlet UILabel *FirstiPhoneapp;
@property (strong, nonatomic) IBOutlet UILabel *ByJ;
@property (strong, nonatomic) IBOutlet UIButton *ClickToStart;
@property (strong, nonatomic) IBOutlet UIButton *Reset;
@property (strong, nonatomic) IBOutlet UIButton *Terminate;
@property (strong, nonatomic) IBOutlet UIButton *Restart;
@end
ViewController.m:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
-(IBAction)Start:(id)sender
{
Timer = [NSTimer scheduledTimerWithTimeInterval:1 target: self selector:@selector(TimerCount) userInfo: nil repeats:YES];
}
- (void)TimerCount {
CountNumber = CountNumber + 1;
TimerDisplay.text=[NSString stringWithFormat:@"%i", CountNumber];
}
- (IBAction)UIImage:(id)sender {
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Images.jpg"]];
if (CountNumber < 6);
Images.hidden = YES;
}
- (IBAction)Stop:(id)sender{
[Timer invalidate];
TimerDisplay.text=[NSString stringWithFormat:@"%i", CountNumber];
}
- (IBAction)Reset:(id)sender{
CountNumber = 0;
[Timer invalidate];
CountNumber = 0;
[Timer invalidate];
TimerDisplay.text = [NSString stringWithFormat:@"%i", CountNumber];
Timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(TimerCount) userInfo:nil repeats:YES];
[Timer invalidate];
}
- (IBAction)Restart:(id)sender{
CountNumber = 0;
TimerDisplay.text = [NSString stringWithFormat:@"%i", CountNumber];
CountNumber = 0;
Timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(TimerCount) userInfo:nil repeats: YES];
if (CountNumber < 6);
Images.hidden = YES;
}
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
而且,出于某种原因,并在此的任何帮助将是有帮助,我得到一个错误[super viewDidLoad];
Xcode是说它“预期的方法体”。我一直在环顾四周,无法找到解决这个问题,任何人都可以帮我解决这个错误?
即使代码不能编译,图像仍然出现?这是令人惊讶的。与c中一样,objective-c代码使用{花括号}分隔。这是viewDidLoad的问题。 – danh 2014-10-08 02:12:55
您的代码质量确实很差 - 您的分号会导致不需要的行为。你也不应该重复相同的路线。 – Szu 2014-10-08 08:32:40