JSON을 사용하여 내 호스트의 서버에서 내용을로드하는 TableViewController가 있습니다. 모든 것이 올바르게 작동하지만 UIImage가 내 레이블 위에로드되어야합니다. 왜 이런 일이 발생하며 어떻게 개체의 순서를 변경합니까? 내 스토리 보드에 모든 내용이 정확합니다.이 변경은 컨텐츠가로드 된 경우에만 발생합니다.UIImage가 레이블보다 많이로드합니다.
이것은 코드입니다.
- (void)viewDidLoad
{
[super viewDidLoad];
// CHECK INTERNET CONNECTION
if ([self IsConnected]) {
[self retrieveData];
}
else {
UIAlertView *alerta = [[UIAlertView alloc] initWithTitle:@"MSG ERRO" message:@"Conecte a Internet" delegate:nil cancelButtonTitle:@"fechar" otherButtonTitles:nil, nil];
[alerta show];
}
}
#pragma mark - PULL TO REFRESH
- (void)refresh
{
if ([self IsConnected]) {
[self retrieveData];
[self.refreshControl endRefreshing];
}
else {
UIAlertView *alerta = [[UIAlertView alloc] initWithTitle:@"MSG ERRO" message:@"Conecte a Internet" delegate:nil cancelButtonTitle:@"fechar" otherButtonTitles:nil, nil];
[alerta show];
[self.refreshControl endRefreshing];
}
}
#pragma mark - CHECK INTERNET CONNECTION METHOD
- (BOOL)IsConnected
{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [reachability currentReachabilityStatus];
return !(networkStatus == NotReachable);
}
#pragma mark - TABLE VIEW
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return programacaoArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"TableCell";
TableCell *cell = (TableCell *)[self.tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[TableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
cell.backgroundColor = [UIColor clearColor];
// CONFIGURE THE CELL
Programacao *programacaoObject;
programacaoObject = [programacaoArray objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:programacaoObject.programacaoImagem]]];
cell.nomeLabel.text = programacaoObject.programacaoNome;
cell.dataLabel.text = programacaoObject.programacaoData;
cell.localLabel.text = programacaoObject.programacaoLocal;
return cell;
}
#pragma mark - LOADS THE DATA FROM SERVER
- (void) retrieveData
{
NSURL *url = [NSURL URLWithString:getDataURL];
NSData *data = [NSData dataWithContentsOfURL:url];
jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
// SETUP programacaoArray
programacaoArray = [[NSMutableArray alloc] init];
// Loop Array
for (int i = 0; i < jsonArray.count; i++) {
// Cria o PROGRAMACAO Objeto
NSString *pID = [[jsonArray objectAtIndex:i] objectForKey:@"id"];
NSString *pNome = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoNome"];
NSString *pImagem = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoImagem"];
NSString *pDescricao = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoDescricao"];
NSString *pData = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoData"];
NSString *pLocal = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoLocal"];
NSString *pPrecos = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoPrecos"];
// ADD THE CONTENT
[programacaoArray addObject:[[Programacao alloc] initWithNome:pNome andImagem:pImagem andDescricao:pDescricao andData:pData andLocal:pLocal andPrecos:pPrecos andID:pID]];
}
// RELOAD TABLE VIEW
[self.tableView reloadData];
}
여기 내 화면입니다.
'TableCell' 클래스의 레이아웃을 사용합니까? –
아니요. IBOutlet을 .h 파일로 만듭니다. '@property (강하고 비 구조) IBOutlet UILabel * nomeLabel; @property (강하고 비 구조) IBOutlet UILabel * dataLabel; @property (강하고 비 구조) IBOutlet UILabel * localLabel; @property (강하고 비 구조) IBOutlet UIImageView * atracaoImagem; 그리고 내 .m 파일에는 아무것도 없습니다. –