我昨天问了一个关于我的表格视图以及将独特的详细视图链接到表格视图中的每个单元格的问题。我相信我在这里的问题得到了很好的回答。(希望你能阅读那篇文章,看看我需要什么)。基本上我想知道我是否正确地制作了我的单身人士。这是我的代码:
timerStore.h
#import "Tasks.h"
@interface timerStore : NSObject
{
NSMutableDictionary *allItems;
}
+(timerStore *)sharedStore;
-(NSDictionary *)allItems;
-(NSTimer *)createTimerFor:(Tasks *)t inLocation: (NSIndexPath *)indexPath;
-(void)timerAction;
@end
timerStore.m
@implementation timerStore
+(timerStore *)sharedStore{
static timerStore *sharedStore = nil;
if (!sharedStore)
sharedStore = [[super allocWithZone:nil]init];
return sharedStore;
}
+(id)allocWithZone:(NSZone *)zone{
return [self sharedStore];
}
-(id)init {
self = [super init];
if (self) {
allItems = [[NSMutableDictionary alloc]init];
}
return self;
}
-(NSDictionary *)allItems{
return allItems;
}
-(NSTimer *)createTimerFor:(Tasks *)t inLocation: (NSIndexPath *)indexPath {
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:t.timeInterval target:self selector:@selector(timerAction) userInfo:nil repeats:1.0];
[allItems setObject:timer forKey:indexPath];
return timer;
}
-(void)timerAction{
//custom properties here
}
@end
我有点困惑,因为我的印象是,当您向下滚动(出列)时,单元格的索引路径会被回收。不过我可能是错的。无论如何,我是否按照链接中的建议制作单身人士的正确道路?