我正在研究一個非常簡單的iOS應用程序,以使我開始編程。這是一個基於標籤的應用程序,因此有一個MainWindow.xib以及一個FirstView.xib和SecondView.xib。所有這些都發生在第一視圖中。我想向第一個視圖添加一個進度條,並且當我添加該對象時,它將自己附加到FirstView.xib並顯示並讓我移動它。爲了測試,alpha設置爲1.00,進度設置爲0.5。無論如何,無論我做什麼,它都不會出現。我究竟做錯了什麼?製作進度視圖可見
AppDelegate.m:
@synthesize window=_window;
@synthesize tabBarController=_tabBarController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Add the tab bar controller's current view as a subview of the window
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
}
- (void)applicationWillTerminate:(UIApplication *)application
{
}
- (void)dealloc
{
[_window release];
[_tabBarController release];
[super dealloc];
}
@end
FirstViewController.h:
#import <UIKit/UIKit.h>
NSTimer *stopWatchTimer;
NSDate *startDate;
@interface FirstViewController : UIViewController {
UILabel *label;
UILabel *stopWatchLabel;
UIProgressView *progressBar;
UIButton *topButton;
}
@property (nonatomic, retain) IBOutlet UILabel *stopWatchLabel;
@property (nonatomic, retain) IBOutlet UIProgressView *progressBar;
- (IBAction)onStartPressed:(id)sender;
- (IBAction)onStopPressed:(id)sender;
- (IBAction)onResetPressed:(id)sender;
@end
FirstViewController.m
#import "FirstViewController.h"
@implementation FirstViewController
@synthesize progressBar;
@synthesize stopWatchLabel;
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.*/
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload
{
[self setStopWatchLabel:nil];
[topButton release];
topButton = nil;
[super viewDidUnload];
// Release any[progress release];
progressBar = nil;
[progressBar release];
progressBar = nil;
[self setProgressBar:nil];
//retained subviews of the[self setProgressBar:nil];
// e.g. self.myOutlet = nil;
}
static NSInteger counter=0;
static NSInteger secs=0;
static NSInteger mins=0;
static NSInteger hrs=0;
- (void)dealloc
{
[stopWatchLabel release];
[label release];
[topButton release];
[super dealloc];
}
-(void)updateTimer {
//updates the timer }
-(void)clearTimer {
//clears the timer
}
-(void)stopTimer{
//stops the timer }
- (IBAction)onStartPressed:(id)sender {
//[email protected]"Start Pressed";
progressBar.alpha=1.0;
//run timer }
- (IBAction)onStopPressed:(id)sender {
[self stopTimer];
}
- (IBAction)onResetPressed:(id)sender {
[self stopTimer];
[self clearTimer];
}
@end
當我們不知道自己在做什麼時,我們應該如何知道自己做錯了什麼?如果您發佈一些代碼,幫助您更容易。否則,我們只是在黑暗中拍攝。 – 2011-04-13 20:21:18
您要麼不將FirstView的視圖控制器添加到選項卡控制器,要麼因爲Erik提到不將進度條添加爲FirstView的子視圖。如果你做得很好,我們需要看到更多的信息,比如代碼來理解問題。 – 2011-04-13 20:31:36
我將代碼添加到委託和視圖控制器。如果需要,我也可以將.xib文件附加到某處。 – Laxsnor 2011-04-13 20:41:22