2011-07-21 8 views
0

(5,10,20)のようなミニッツで時間を表示しているpickerviewがあります。ユーザーが任意の時間を選択すると、選択した時間後に更新を取得します。私のアプリケーションはいつものように実行されますが、5分後にメッセージにいくつかの更新が表示されます。iphoneアプリで "更新を確認する"のコンセプトを実装する方法

この概念をどのように実装しますか?私はどんなコーディングをするべきですか?

私の推測によれば、スレッド化する必要がありますか?

答えて

1

ピッカービューから時間を選択するとNSTimerが起動します。

あなたは何の繰り返しを選択していないし、あなたのupdateMethodにあなたが要求します
timer = [NSTimer scheduledTimerWithTimeInterval:pickerValueInSeconds target:self selector:@selector(updateMethod) userInfo:nil repeats:NO]; 

-(void)updateMethod 
{ 
    NSString *url = @"url..."; 
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:someURL] 
             cachePolicy:NSURLRequestUseProtocolCachePolicy 
              timeoutInterval:20.0]; // with some timeout interval. 

    // create the connection with the request 
    // and start loading the data 
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

    if(theConnection) 
    { 
     // Create the NSMutableData to hold the received data. 
     // receivedData is an instance variable declared elsewhere. 
     systemsData = [[NSMutableData data] retain]; 
    } 
    else 
    { 
     // Inform the user that the connection failed. 
     NSLog(@"NSURLConnection failed!"); 
    } 

} 

を今すぐあなたの

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 

にあなたが世話をしますデータまたはエラーをEWタイマー..あなたもあなたがNSTimerを作成して、選択した期間を待つことができ

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [systemsData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [systemsData appendData:data]; 
} 
+0

素晴らしい作品です。ありがとう –

0

を実装する必要が

注意。タイムアウトが完了すると、

scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: 

メッセージがセレクタに送信されます。 Googleにはたくさんのサンプルコードがあります。

関連する問題