所以我有一个简单的用户界面,一个开始按钮,一些文本/标签和一个进度条。单击“开始”按钮时,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
答案 0 :(得分:10)
转到进度指示器的属性检查器并进行设置,如下图所示:
见下面的代码:
@synthesize progressBar;
- (IBAction)startAction:(id)sender {
[progressBar setHidden:NO];
[progressBar setIndeterminate:YES];
[progressBar setUsesThreadedAnimation:YES];
[progressBar startAnimation:nil];
}