- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSString *country=[[NSUserDefaults standardUserDefaults]objectForKey:@"namecountry"];
//url's
NSURL *url = [NSURL URLWithString:@"someurl"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:country forKey:@"c_name"];
[request setRequestMethod:@"POST"];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request startSynchronous];
NSString *response = [request responseString];
NSLog(@"%@",response);
res=[[response componentsSeparatedByString:@","] retain];
NSLog(@"%@",[res objectAtIndex:18]);
show=[NSString stringWithFormat:@"%@",[res objectAtIndex:18]];
float f=[show floatValue];
show=[NSString stringWithFormat:@"%.2f %%",f];
[show retain];
}
이것은 정보를 보여주는 두 번째 탭입니다.하지만 그것을 클릭하면 가끔 업데이트됩니다. 나는 임의로 추측합니다. 모든 시간을 업데이트하고 싶습니다. 사용을 말하지 마십시오. [self.tableView reloadData]; 탭 바 아이콘을 클릭하면 해당 메서드를 호출하므로 다시 작성할 필요가 없습니다.이 함수는 내 viewDidAppear입니다. Nslog 로그는 업데이트 된 값을 제공하므로 테이블 셀을 업데이트하지 않습니다.tableviewcell이 업데이트되지 않는 이유는 무엇입니까?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
if (indexPath.row % 2 == 0) {
// EVEN
cell = [tableView dequeueReusableCellWithIdentifier:@"EvenCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"EvenCell"] autorelease];
UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
UIColor *colour = [[UIColor alloc] initWithRed: (208.0/255.f) green: (231.0/255.f)
blue: (241.0/255.f) alpha: 1.0];
bg.backgroundColor = colour;
cell.backgroundView = bg;
cell.textLabel.backgroundColor = bg.backgroundColor;
[bg release];
cell.detailTextLabel.backgroundColor=[UIColor clearColor];
cell.detailTextLabel.text=show;
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else {
// ODD
cell = [tableView dequeueReusableCellWithIdentifier:@"OddCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"OddCell"] autorelease];
UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
UIColor *colour = [[UIColor alloc] initWithRed: (143.0/255.f) green: (169.0/255.f)
blue: (180.0/255.f) alpha: 1.0];
bg.backgroundColor = colour;
cell.backgroundView = bg;
cell.textLabel.backgroundColor = bg.backgroundColor;
[bg release];
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
이 셀은 내가 작성하는 셀입니다. cell.detailTextLabel.text = show; 그래서 그것은 업데이 트 값을 표시 할 수 있지만 내가 말했듯이 무작위로 업데이 트됩니다. 아무도 문제가 어디 있는지 말해 줄 수 있습니까? btw 나는 홀수 셀을 사용하지 않는다. 단지 개념 일 뿐이다.
사용자가 탭 바를 선택할 때마다 업데이트되지 않는 이유를 확인해 주셔서 감사합니다. –
그들은 값이 바로 cellforrowatindexpath에 오는 것입니다 –
그 경우에는 코드에 아무런 문제가 없습니다. 문제가 있는지 앱의 다른 곳에서 확인해야합니다. – memmons