Здравствуйте, у меня есть табличное представление с пользовательской ячейкой, и я хочу, чтобы в реальном времени обновлял мои коды.Objective-c TableView реального времени обновить пользовательские ячейки
@interface ViewController() <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *jsonArray;
@property (nonatomic, strong) NSMutableArray *array1;
@property (nonatomic, strong) NSDictionary *entryDict;
@end
- (void)viewDidLoad {
[super viewDidLoad];
_tableView.delegate = self;
[self refresh];
}
- (void)refresh
{
NSString *urlduzenli = [NSString stringWithFormat:@"http://bla.com/server/table.php?OrderId=%@",suankioturumid];
NSURL * url = [NSURL URLWithString:urlduzenli];
NSURLRequest * urlReq = [NSURLRequest requestWithURL:url];
NSError * error;
NSData * data = [NSURLConnection sendSynchronousRequest:urlReq returningResponse:nil error:&error];
if (!error) {
NSDictionary * jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
_jsonArray = [jsonDict objectForKey:@"orders"];
_array1 =[[NSMutableArray alloc]init];
}else{
}
[self.tableView reloadData];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _jsonArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"CustomCell";
CustomTableViewCell *cell=(CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid];;
if(cell==nil)
{
cell=[[CustomTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid];
}
_entryDict= _jsonArray[indexPath.row];
NSString *countryName = _entryDict[@"order"];
NSMutableSet *seenCharacters = [NSMutableSet set];
NSMutableString *resultf = [NSMutableString string];
cell.nameLabel.text= countryName;
if([cell.nameLabel.text isEqualToString:@"1"]){
cell.nameLabel.backgroundColor = [UIColor redColor];
}else{
}
return cell;
}
Коды успеха в работе Мне нужно только обновлять таблицы в реальном времени. Im все еще работающ около 8-10 часов но я не разрешил его.
Не обновляйте каждую ячейку
(мою ошибку это: Показаны красного фона на неправильных строках при добавлении новых строк)
if([cell.nameLabel.text isEqualToString:@"1"]){
cell.nameLabel.backgroundColor = [UIColor redColor];
}
Спасибо за помощь! Спасибо
Итак, что конкретно представляет собой ваш вопрос? Вы просто хотите обновить данные во всей таблице? Один ряд? –
@MSU_Bulldog весь стол чувак – SwiftDeveloper
Существует метод для этого ... '[tableView reloadData];' –