У меня есть UITableview
, и я заполняю UITableview
значениями из веб-службы. Мои UILABEL
правильно заполнены правильными данными.Обновить UItableview не обновляет ярлык
Моя проблема в том, что когда я пытаюсь обновить ecolor UILabel
, ничего не происходит?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"nil";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil)
{
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] ;
}
self.tableView.separatorInset = UIEdgeInsetsZero;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
// Sets the Label for the cell
self.hungryPersonOrderStatusLabel = [[UILabel alloc] init];
self.hungryPersonOrderStatusLabel.frame = CGRectMake(80, 30, 150, 25);
self.hungryPersonOrderStatusLabel.backgroundColor = [UIColor clearColor];
self.hungryPersonOrderStatusLabel.textAlignment = NSTextAlignmentJustified;
self.hungryPersonOrderStatusLabel.font = [UIFont fontWithName:@"SegoeWP" size:13.0];
self.hungryPersonOrderStatusLabel.textAlignment = NSLineBreakByTruncatingTail;
self.hungryPersonOrderStatusLabel.numberOfLines = 1;
self.hungryPersonOrderStatusLabel.text = [[self.viewOrderUserArray valueForKey:@"OrderStatus"] objectAtIndex:[indexPath row]];
self.hungryPersonOrderStatusLabel.tag = 1001;
self.hungryPersonOrderStatusLabel.textColor = [UIColor appGreenColor];
[cell.contentView addSubview:self.hungryPersonOrderStatusLabel];
}
-(void)getOrderDetails
{
[self showSpinner];
DeliNinjaWebService *webService = [DeliNinjaWebService alloc];
[webService viewOrderDetails:self.deli.deliId success:^(NSArray *response)
{
NSLog(@"Response Object %@",response);
[self hideSpinner];
self.viewOrderDetailsArray = [response mutableCopy];
self.viewOrderUserArray = [[response valueForKeyPath:@"Orders"] mutableCopy];
NSString *orderStatusString = [[self.viewOrderUserArray valueForKey:@"OrderStatus"] componentsJoinedByString:@""];
if ([orderStatusString isEqualToString:@"In Progress"])
{
self.hungryPersonOrderStatusLabel.textColor = [UIColor appRedColor];
[self.tableView reloadData];
}
[self.tableView reloadData];
} failure:^(NSString *error)
{
[self hideSpinner];
NSLog(@"Fail %@", error);
} noConnection:^
{
[self hideSpinner];
[self showMessage:@"No Connection Error" Message:@"Please check your internet connection"];
}];
}
и я попытался добавить ярлык здесь, а затем добавить подвью, но ничего не произошло, так как табличное представление не обновлялось.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"nil";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
self.hungryPersonOrderStatusLabel = [[UILabel alloc] init];
self.hungryPersonOrderStatusLabel.frame = CGRectMake(80, 30, 150, 25);
self.hungryPersonOrderStatusLabel.backgroundColor = [UIColor clearColor];
self.hungryPersonOrderStatusLabel.textAlignment = NSTextAlignmentJustified;
self.hungryPersonOrderStatusLabel.font = [UIFont fontWithName:@"SegoeWP" size:13.0];
self.hungryPersonOrderStatusLabel.textAlignment = NSLineBreakByTruncatingTail;
self.hungryPersonOrderStatusLabel.numberOfLines = 1;
self.hungryPersonOrderStatusLabel.tag = 1001;
self.hungryPersonOrderStatusLabel.textColor = [UIColor appGreenColor];
[self.hungryPersonOrderStatusLabel setTag:999];
}
UILabel *label = (UILabel *)[cell.contentView viewWithTag:999];
label.text = [[self.viewOrderUserArray valueForKey:@"OrderStatus"] objectAtIndex:[indexPath row]];
}
Спасибо. Да, моя проблема заключалась в установке цвета текста в методе CellForRow таблицы. Когда я перезагружу свой табличный просмотр, он снова прочитает код в этом методе. – CapeFurSeal
Ваш прием !!! – nikhil84