我正在尝试使用单例保存按钮的名称,以便可以在另一个视图中访问该名称以播放具有相同名称的视频。但是,我收到错误:SIGABRT。我真的没有看到我的代码有什么问题。有任何想法吗?
#import "List.h"
#import "MyManager.h"
#import "Video.h"
@implementation ExerciseList
-(IBAction) goToVideo:(UIButton *) sender{
MyManager *sharedManager = [MyManager sharedManager];
sharedManager.vidName = [[sender titleLabel] text];
Video *videoGo = [[Video alloc] initWithNibName: @"Video" bundle: nil];
[self.navigationController pushViewController: videoGo animated: YES];
[videoGo release];
}
这是MyManager的.h和.m:
#import <foundation/Foundation.h>
@interface MyManager : NSObject {
NSMutableArray *workouts;
NSString *vidName;
}
@property (nonatomic, retain) NSMutableArray *workouts;
@property (nonatomic, retain) NSString *vidName;
+ (id)sharedManager;
@end
#import "MyManager.h"
static MyManager *sharedMyManager = nil;
@implementation MyManager
@synthesize workouts;
@synthesize vidName;
#pragma mark Singleton Methods
+ (id)sharedManager {
@synchronized(self) {
if (sharedMyManager == nil)
sharedMyManager = [[self alloc] init];
}
return sharedMyManager;
}
- (id)init {
if ((self = [super init])) {
workouts = [[NSMutableArray alloc] init];
vidName = [[NSString alloc] init];
}
return self;
}
-(void) dealloc{
self.workouts = nil;
self.vidName = nil;
[super dealloc];
}
@end
答案 0 :(得分:0)
您应该访问按钮的标题
sharedManger.vidName = [sender currentTitle];
但是,您不使用ARC,因此请检查您的vidName属性为retain
或复制的位置。
如果它没有保留或复制,那么你也可以使用这个代码
if(sharedManger.vidname != nil){
[sharedManger.vidName release];
sharedManger.vidName = nil;
}
sharedManger.vidName = [[sender currentTitle] retain];