싱글 톤 NSMutableArray를 만들려고합니다. 그래서 TableView에서 타이틀로 사용할 수 있습니다. TableView에서 선언하는 방법?싱글 톤을 사용하여 배열을 만들고 TableView에서 선언하십시오.
예컨대
cell.textLabel.text = ??? //Don't know how to declare it from the singleton.
여기 내 singleton.m입니다 :
#import "Singleton.h"
@implementation Singleton
@synthesize Trees;
+(Singleton *) theTrees {
static dispatch_once_t pred;
static Singleton *theTrees = nil;
dispatch_once(&pred,^{
theTrees = [[Singleton alloc] init];
theTrees.Trees = [[NSMutableArray alloc] init];
});
return theTrees;
}
-(id) init {
self = [super init];
if(self) {
// Variables
[Trees addObject:@"Berzas"];
[Trees addObject:@"Liepa"];
[Trees addObject:@"Drebule"];
}
return self;
}
@end
가 올바른 방향으로 날 가리하시기 바랍니다, 감사합니다.
나는 당신이하고있는 일이나 그 이유를 정확히 알지 못한다고 생각합니다. – Merlevede
이 시점에서, 스택 오버플로에서 발견 된 여러 가지 메서드를 시도했기 때문에 제발 이해할 수 있습니다. 저는 초보자이며 도움이 필요합니다. – MariusJusc
이해하지만, 말이 되네. 싱글 톤에서'cell.textLabel.text'에 텍스트를 넣고 싶지만 싱글 톤에는 배열이 들어 있습니다. 또한 여러분의 싱글 톤은 실제로 싱글 톤이 아닙니다. 여전히'init'을 사용하여 객체를 인스턴스화 할 수 있기 때문입니다. 또한'Trees' 객체는 초기화되지 않았기 때문에 충돌합니다. – Merlevede