0
我有一個叫RSTimer
類有兩個方法稱爲CreateTimer
和KillTimer
它使用相同的字典對象。我無法在接口中以及在實現中聲明變量。它在聲明中指出並說這不是一個常數。如何使共同聲明的講座的兩種方法>目標C
-(BOOL)KillTimer:(unsigned short)wTimerId
{
stRs232Timer* pEvent;
BOOL bReturn=FALSE;
CFDictionaryValueCallBacks cbs = {0,NULL,NULL,NULL,NULL};
CFMutableDictionaryRef cfdict = CFDictionaryCreateMutableNULL,0,&kCFTypeDictionaryKeyCallBacks,&cbs);
NSLock* theLock = [[NSLock alloc]init];
if ([theLock tryLock]) {
if (CFDictionaryContainsKey(cfdict,&wTimerId)) {
free(pEvent);
bReturn = TRUE;
}
[theLock unlock];
}
return bReturn;
}
-(BOOL)CreateTimer:(RS232TimerInterface*)pStack withTimerId:(unsigned short)wTimerId withPeriod:(uint8_t)uPeriod withPersistentState:(BOOL)bPersistent
{
CFDictionaryValueCallBacks cbs = {0,NULL,NULL,NULL,NULL};
CFMutableDictionaryRef cfdict = CFDictionaryCreateMutable(NULL,0,&kCFTypeDictionaryKeyCallBacks,&cbs);
CFNumberRef timerId = CFNumberCreate(NULL,kCFNumberShortType,&wTimerId);
[self KillTimer:wTimerId];
NSLock* theLock = [[NSLock alloc]init];
if ([theLock tryLock]) {
CFDictionarySetValue(cfdict,&timerId,pEvent);
[theLock unlock];
}
}
我試過在'init'方法中聲明它。我怎樣才能讓
CFDictionaryValueCallBacks cbs = {0,NULL,NULL,NULL,NULL};
CFMutableDictionaryRef cfdict = CFDictionaryCreateMutable(NULL,0,&kCFTypeDictionaryKeyCallBacks,&cbs);
兩者共同的方法..
謝謝...你說的那樣,它的工作原理... – spandana 2011-05-16 12:34:29