Why is tableviewcell not being updated?
- (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];
}
This is the second tab that show the information.But when i click it it doesn't update sometimes it updates its random i guess.I want it to update every time.And please don't tell me to use [self.tableView reloadData]; When i click the tab bar icon i know it calls that method so no need to rewrite.This function is my viewDidAppear. Nslog log gives the updated value right so why it is not updating the table cell.
- (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.backgrou开发者_高级运维ndColor;
[bg release];
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
This one is the function that i create the cells i write cell.detailTextLabel.text=show; so it can show the updating value but as i said it is randomly update or not.Can anybody tell me where is the problem? btw i don't use the odd cell for now it is just concept.
There is no retain problem with this code, but if you are having problems with the cell refreshing here are things I would try if it were my code:
- Confirm that
cellForRowAtIndexPath
is being called NSLog()
the results of[array objectAtIndex:indexPath.row]
right before you assign it to the label and confirm that the value is the expected value.
精彩评论