2010-09-11 62 views
0

在埃裏卡Sadun的下載助手,link here,我可以把這些方法到我的班:iPhone SDK - 異步下載方法

- (void) didReceiveData: (NSData *) theData; 
- (void) didReceiveFilename: (NSString *) aName; 
- (void) dataDownloadFailed: (NSString *) reason; 
- (void) dataDownloadAtPercent: (NSNumber *) aPercent; 

這些方法顯然是指回「DownloadHelper.h」和「DownloadherHelper.m 」。我想知道我是否能夠訪問xib視圖上的屬性,如textfields,uitableviews,uilabels等等。例如:

- (void) didReceiveFilename: (NSString *) aName { 
    [label setText:@"hi"]; 
} 

我試過這樣做,但xib視圖上的對象不會更新。就像上面給出的例子一樣。有沒有辦法做到這一點?

感謝,

凱文

+0

你介意更新這個問題提供有關的實際原因的一些細節(代碼)問題? – Greg 2010-09-13 00:18:35

回答

1

應該可以訪問/更新您從廈門國際銀行鏈接到您的控制器的任何網點的屬性。您是否通過調試器驗證了didReceiveFilename:消息正發送到您的控制器,並且label在發送消息setText:時不爲零?

編輯:我與離線發佈此問題的人溝通。該問題與異步下載無關。他的代碼試圖通知包含表視圖的視圖的控制器,表明下載已經開始,但是該消息被髮送給錯誤的控制器實例。解決這個問題已經解決了。

從這個更改:

// code that switched to an existing DownloadViewController omitted... 
    // the new download controller that is created here has no views seen by the user! 
    DownloadViewController *download = [[DownloadViewController alloc] init]; 
    [download downloadstart]; 

向該:

// code that switched to an existing DownloadViewController omitted... 
    // use the existing DownloadViewController instead of creating a new one 
    DownloadViewController *download = (DownloadViewController *)[[appDelegate.rootController viewControllers] objectAtIndex:1]; 
    [download downloadstart]; 

downloadstart方法負責更新在Kevin的代碼表視圖。

+0

是的,我已經調試了斷點,他們都是積極的。而不是[label setText:@「hi」];代碼我實際上使用下面的代碼來創建一個單元格:[data addObject:name]; [self saveData]; [mainTableView reloadData]; – lab12 2010-09-11 23:06:27

0

UI更新需要在主線程的地方,你應該嘗試

performSelectorOnMainThread:withObject:waitUntilDone:

[label performSelectorOnMainThread:@selector(setText:) 
      withObject:@"hi" waitUntilDone:NO]; 
+0

你知道我認爲這將是解決方案,但它仍然無法正常工作。我實際上並沒有試圖更新標籤,我試圖在這裏更新代碼:http://stackoverflow.com/questions/3691074/iphone-sdk-nsmutablearray-addobject-sometimes-works ...這是與一個UITableView。 – lab12 2010-09-12 06:49:12