我創建NSTimer
:我可以在另一個NStimer中使用NStimer嗎?
timer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(sendImage) userInfo:nil repeats:YES];
在該方法sendImage
,我創建另一個NSTimer
timer2
。代碼如下:
- (void)sendImage
{
for(int i = 0;i < 50 ; i++)
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:socket forKey:@"socket"];//parameter which deliver to the method`sendPieceOfImage`
[dict setObject:pData forKey:@"pData"];
timer2 = [NSTimer scheduledTimerWithTimeInterval:0.002f target:self selector:@selector(sendPieceOfImage:) userInfo:dict repeats:NO];
}
}
但它沒有奏效。我想知道NSTimer
可以機械地應用嗎?如果不可行,我可以在sendImage
中做什麼。我希望for()
中的每個循環都可以間隔運行。
「但它沒有工作」 - 它產生了一個錯誤,炸燬,炒雞蛋;-)等?細節將幫助人們幫助你。編輯您的問題以添加詳細信息,並且有人可能會提供幫助。 – CRD
第一個計時器是否正常工作?調用sendImage方法嗎? –
您正在重新創建計時器50次?這應該如何工作? – trojanfoe