9

所以我有一个简单的用户界面、一个开始按钮、一些文本/标签和一个进度条。单击“开始”按钮时,NSProgressIndicator应该动画。这是我的代码:

@synthesize progressBar = progressBar;
 /* Some code and setup stuffs... */
- (IBAction)startAction:(id)sender {
    NSLog(@"Button clicked.");
    NSLog(@"Beginning Socketry and socket creation...");
    [progressBar setUsesThreadedAnimation:YES];
    [progressBar setIndeterminate:YES];
    [progressBar startAnimation:progressBar];
}

我检查了多个来源(Apple Developer Portal 等),但没有任何效果。我不必拥有 NSPIndicator,但如果可以的话,那就太好了。另外,这是我的 AppDelegate.h 文件:

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;

@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (weak) IBOutlet NSProgressIndicator *progressBar;
- (IBAction)saveAction:(id)sender;

- (IBAction)startAction:(id)sender;

- (IBAction)changeStatus:(id)sender;

- (IBAction)changeProgress:(id)sender;

@end
4

1 回答 1

14

进入 Progress Indicator 的 Attributes Inspector,如下图所示进行设置:

在此处输入图像描述

请参见下面的代码:

@synthesize progressBar;
- (IBAction)startAction:(id)sender {
    [progressBar setHidden:NO];
    [progressBar setIndeterminate:YES];
    [progressBar setUsesThreadedAnimation:YES];
    [progressBar startAnimation:nil];
}
于 2014-06-12T10:35:58.327 回答