昨天我问了一个关于我的表视图的问题,并将唯一的细节视图链接到表视图中的每个单元格。我相信我对我的问题here得到了很好的回答。 (希望你可以阅读这篇文章,看看我需要什么)。基本上我想知道如果我正确地做我的单身人士。这里是我的代码:我在单身人士的正确轨道上吗?
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
我有点困惑,因为我的印象是,一个小区的索引路径当您向下滚动(出列)时会被回收。但我可能是错的。无论如何,我在正确的道路上建立一个单身男人作为link建议的人?
你知道,我一直在编程,现在4年iOS的 - 在工作半打不同的大型应用。我还没有需要使用单身。 –
特别是,如果你有一个表格视图,你必须有一个视图控制器。该视图控制器可以包含表格的数据(作为委托)。单身人士不需要存储表格数据。 –
是的,我想避免使用单身人士,但我不知道如何做到这一点。基本上即时使用NSFetchedResultsController填充表视图(链接到UIViewController子类)。每个单元格应在其详细视图中有一个计时器(由didSelectRowAtIndexPath产生)。显然单身是确保多个计时器可以共存并通过将详细视图限制为一个初始化来减少内存使用的最佳方式......更多信息请参阅OP – EvilAegis