UIImage加载标签

时间:2014-04-30 14:48:16

标签: cocoa-touch uiimageview uitableview

我有一个TableViewController,可以使用JSON从我主机上的服务器加载内容。 一切都正常,但是UIImage应该在所有标签下面加载。 为什么会发生这种情况?如何更改objetcs的顺序? 在我的故事板中,一切都是正确的,只有在加载内容时才会发生这种变化。

这是代码。

- (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

1 个答案:

答案 0 :(得分:0)

您确定programacaoObject.programacaoNomeprogramacaoObject.programacaoDataprogramacaoObject.programacaoLocal不是空的吗?