我正在製作一個非常簡單的應用程序。我有一個計時器,當計時器超過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