2014-04-30 91 views
0

我有一個TableViewController從主機上的服務器使用JSON加載內容。 一切工作正常,但UIImage應該在所有下載我的標籤上。 爲什麼會發生這種情況,如何更改objetcs的順序? 在我的故事板中,所有內容都是正確的,只有在加載內容時纔會發生此更改。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]; 

}

這裏是我的屏幕。 enter image description here

+0

你是否在TableCell類中做過任何佈局? –

+0

不,我只是在.h文件中創建我的IBOutlets。 '@property(strong,nonatomic)IBOutlet UILabel * nomeLabel; @property(強,非原子)IBOutlet UILabel * dataLabel; @property(強,非原子)IBOutlet UILabel * localLabel; @property(強,非原子)IBOutlet UIImageView * atracaoImagem;'沒有在我的.m文件。 –

回答

0

您確定,programacaoObject.programacaoNome,programacaoObject.programacaoDataprogramacaoObject.programacaoLocal不是空的嗎?

+0

是的,因爲如果我評論加載圖像的行。標籤正常顯示 –