-1

別の行の行が選択されているUITableViewときにリロードしようとしています。UITableView's私が抱えている問題の 1 つは、両方がUITableView's同じビューにあることです。NSMutableArrayTable1 での選択を変更して、 Table2 の設定に使用するものを変更したいと考えています。そして、テーブルをリロードします。

現時点では問題なく動作しますが、アプリが再起動されたとき (またはビューがスタックからポップされてから再度アクセスされたとき) にのみ、viewWillAppear再度呼び出されます

これが私のコードです:

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:NO];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    self.navigationController.toolbarHidden = YES;
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

    // getting an NSString
    selectedTableString = [prefs stringForKey:@"selectedTableString"];
    if ([selectedTableString isEqualToString:@"Italy"]) {
        jsonStringCountry = @"http://****/v1/public/cities?country=it";
    }
    else if ([selectedTableString isEqualToString:@"Spain"]) {
        jsonStringCountry = @"http://****/v1/public/cities?country=es";
    }
    else if ([selectedTableString isEqualToString:@"UK"]) {
        jsonStringCountry = @"http://****/v1/public/cities?country=uk";
    }
    else if ([selectedTableString isEqualToString:@"Brazil"]) {
        jsonStringCountry = @"http://****/v1/public/cities?country=br";
    }
    NSLog(@"from two t selectedTableString %@",selectedTableString);

    // Download the yoodeal JSON
    NSString *jsonString = [NSString stringWithContentsOfURL:[NSURL URLWithString:jsonStringCountry] encoding:NSStringEncodingConversionAllowLossy|NSUTF8StringEncoding error:nil];
    NSLog(@"jsonStringCountry is %@", jsonStringCountry);
    NSMutableArray *itemsTMP = [[NSMutableArray alloc] init];

    // Create parser for the yoodeal api
    SBJSON *parser = [[SBJSON alloc] init];
    NSDictionary *results = [parser objectWithString:jsonString error:nil];
    itemsTMP = [results objectForKey:@"results"];
    self.displayItems = [itemsTMP copy];
}

私のUITableView方法:

- (int)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [displayItems count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];
    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"];
    }

    // Get item from tableData
    NSDictionary *item = (NSDictionary *)[displayItems objectAtIndex:indexPath.row];
    cell.textLabel.text = [item objectForKey:@"name"];
    [cell.textLabel setFont:[UIFont fontWithName: @"Asap-Bold" size: 14.0f]];
    return cell;
}
4

4 に答える 4

1

のデリゲート メソッドを使用する必要がありますUITablveView。メソッドは次のとおりです。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

の行をクリックすると、このメソッドが呼び出されますUITableView。これを次のように使用します。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   if(tableView == Table1)
   {
        //do the changes in array you want to do.
        [table2 reloadData];
   }
   else
   {
        //do the changes in array you want to do.
        [table1 reloadData];
   }
}
于 2013-02-01T11:54:11.697 に答える
1

テーブル ビューのアウトレットを作成する

 [self.yourTableView reloadData];
于 2013-02-01T11:30:23.097 に答える
1

オンクリックを使用[tablename reloadData];します。

テーブルビューの内容を更新する場合、ビューは更新されません。View Controller がリロードされると、変更のみが表示されます。テーブルを即座に更新するには、上記のコードを呼び出す必要があります

于 2013-02-01T11:34:47.233 に答える
1

呼び出される UITableView のプロパティを作成してから、 をsecondTableView使用する必要があります[secondTableView reloadData]

于 2013-02-01T11:35:20.803 に答える