0

このトピックに関するいくつかの質問を見つけましたが、問題が解決したようです。サーバーから XML フィードを取得して解析し、データを 3 つの UITableView に表示する iPhone アプリがあります (解析時に並べ替えが行われます)。現在、データの解析が完了したら、UITables を更新するための NSTimers があります。私はもっ​​と良い方法があることを知っています。パーサーデリゲートメソッドを使用しようとしています

私のParser.mで

    -(void)parserDidEndDocument:(NSXMLParser *)parser{
   NSLog(@"done Parsing, now update UITable in otherViewController");
    otherViewController *otherUpdatingtmp =[[otherViewController alloc] initWithNibName:@"otherViewController" bundle:nil];
    [otherUpdatingtmp updateTable];
    }

updateTableテーブルの reloadData にある otherViewController にあるメソッドをトリガーします。私の NSLog は、私updateTableが otherViewController スレッドで発火していることを教えてくれますが、 TableView が として返されるため、更新するようには見えませんNULL

私のotherViewController.mで

-(void)updateTable{

    [tabeViewUI reloadData];
    NSLog(@"update table fired. table view is %@.", tabeViewUI);

}

それは私が見落としていた小さなものでなければなりません。前もって感謝します!

編集 7/24/12: @tc に感謝します。私を使うようにしてくれて[NSNotificationCenter]

私のparser.mで

-(void)parserDidEndDocument:(NSXMLParser *)parser{
  NSLog(@"done Parsing, now update UITable's with NSNotification");

    [[NSNotificationCenter defaultCenter] postNotificationName:@"parserDidEndDocument" object:self];}

次に、追加した各 UITableViews に次のように入力します。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTable) name:@"parserDidEndDocument" object:nil];

    }
    return self;

}

最後に:

 -(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

これが他の誰かに役立つことを願っています。確かに助かりました!ありがとう@tc。

4

0 に答える 0