0

私は(無駄に)MasterViewController別の View Controller からtableView をリロードしようとしていますSitesViewController。私はでこのコードを使用しますSitesViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row = [[self tableView].indexPathForSelectedRow row];

    //NSArray *appcell = [sitesMenu objectForKey:@"Table"];

    NSLog(@"AppCell %@", sitesMenu);

    NSDictionary *entry = [sitesMenu objectAtIndex:row];



    self.siteid = [entry objectForKey:@"SITEID"];

    NSLog(@" sample SiteView %@", siteid);

    NDSClassMasterViewController *detailControllerTwo = [[NDSClassMasterViewController alloc] init];
    detailControllerTwo.globalid = siteid;

    NSLog(@"message %@", detailControllerTwo.globalid);



    [detailControllerTwo fetchTweets];



    dispatch_async(dispatch_get_main_queue(), ^{
        [detailControllerTwo.tableView reloadData];
        NSLog(@"%@", detailControllerTwo);
    });
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}

そして、私が呼び出しているメソッドのこのコード:

- (void)fetchTweets
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{



        NSString *siteurl = [[NSString alloc] initWithFormat:@"http://adhoc.nyxtek.co.za/spfjsonws/default2.aspx?siteid=%@", globalid];
        NSData* data = [NSData dataWithContentsOfURL:
                        [NSURL URLWithString: siteurl]];

        NSError* error;

        menuItems = [NSJSONSerialization JSONObjectWithData:data
                                                 options:kNilOptions
                                                   error:&error];

        NSLog(@"%@", menuItems);

        dispatch_async(dispatch_get_main_queue(), ^{

            [self.tableView reloadData];
        });
    });
}

リロード コードを SiteViewController didSelectRow メソッドに追加しました。

プロパティを追加して合成する必要があることを読みましたが、それを試しましたが、UITableViewのプロパティを追加して既存のものを参照する方法がわかりません。

fetchTweets コードは実行されますが、TableView はリロードされません。

任意の支援をいただければ幸いです。

編集

これは、セルにアイテムをロードする TableView コードです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"TweetCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    //NSString *name = [[[menuItems objectForKey:@"Table"] objectAtIndex:0] objectForKey:@"MENUID"];
    NSDictionary *tweet = [[menuItems objectForKey:@"Table"] objectAtIndex:indexPath.row];
    //NSLog(@"%@", tweet);

    NSString *text = [tweet objectForKey:@"MENUDESC"];
    NSString *name = [tweet objectForKey:@"MENUDESC"];
    NSLog(@"TEST 1%@", text);
    cell.textLabel.text = text;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"by %@", name];

    return cell;
}
4

1 に答える 1

0

プロパティを介してテーブル ビューを公開する代わりに、データをリロードするコードを含む関数をビュー コントローラー内に単純に記述してみませんか?

EG の代わりに:

    [detailControllerTwo.tableView reloadData];

次のような MasterViewController のメソッドを宣言します。

- (void) updateTable
{
    // tableView is declared as an IBOutlet
    [tableView reloadData];
}

そして、あなたはそれを呼び出すことができます:

dispatch_async(dispatch_get_main_queue(), ^{
    [detailControllerTwo updateTable];
    NSLog(@"%@", detailControllerTwo);
});
于 2013-03-03T11:56:59.573 に答える