Делаем видимость прогресса видимой - PullRequest
0 голосов
/ 14 апреля 2011

Я работаю над очень простым приложением для iOS, чтобы начать программирование.Это приложение на основе вкладок, поэтому есть MainWindow.xib вместе с FirstView.xib и SecondView.xib.Все это происходит на первый взгляд.Я хочу добавить индикатор выполнения в первый вид, и когда я добавил объект, он присоединяется к FirstView.xib, появляется и позволяет мне перемещать его.Чтобы проверить, альфа установлена ​​на 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 {
    //stopWatchLabel.text=@"Start Pressed";
    progressBar.alpha=1.0;
//run timer    }


- (IBAction)onStopPressed:(id)sender {
    [self stopTimer];
}

- (IBAction)onResetPressed:(id)sender {
    [self stopTimer];
    [self clearTimer];
}
@end

1 Ответ

2 голосов
/ 14 апреля 2011

Есть две вещи, которые вам нужно сделать с видом после его создания: Вы должны добавить его как подпредставление видимого вида и установить правильный кадр.

Вот как это сделать:

 [self.view addSubview:progressBar];
progressBar.frame = CGRectMake(x, y, width, height);

РЕДАКТИРОВАТЬ: Возможно, совершенно не связаны с вашим вопросом, но это все неправильно:

- (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;
}

Возможно, вы хотите, чтобы это выглядело примерно так:

- (void)viewDidUnload
{
    [super viewDidUnload];
    [self setStopWatchLabel:nil];
    [topButton release];
    topButton = nil;
    [label release];
    label = nil;
    self.progressBar = nil;
}

Убедитесь, что вы понимаете, что сделали неправильно. Очень важно, чтобы вы поняли это правильно, иначе ваше приложение утечет и / или зависнет.

Остальная часть вашего кода ничего не делает. Вы, кажется, делаете все в IB, так что, я думаю, в этом ваша проблема.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...