別の行の行が選択されているUITableView
ときにリロードしようとしています。UITableView's
私が抱えている問題の 1 つは、両方がUITableView's
同じビューにあることです。NSMutableArray
Table1 での選択を変更して、 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;
}