图片未显示在表格View Cell JSON解析目标C中?

时间:2018-06-27 00:31:47

标签: objective-c uiimageview

#import "LiveScreenViewController.h"
#import "LiveScreenTableViewCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface LiveScreenViewController ()
{
    NSString *mainstr;
    NSMutableArray *player_name;
    NSMutableArray *position;
     NSMutableArray *points;
     NSMutableArray *price_change;
     NSMutableArray *player_photo;
    NSMutableArray *club_name;
    NSMutableArray *mainArray;
    NSDictionary *mainDic;
  }

@end

@implementation LiveScreenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    player_name=[[NSMutableArray alloc]init];
    position=[[NSMutableArray alloc]init];
    points=[[NSMutableArray alloc]init];
    price_change=[[NSMutableArray alloc]init];
    player_photo=[[NSMutableArray alloc]init];
    club_name=[[NSMutableArray alloc]init];
    mainArray=[[NSMutableArray alloc]init];


    [self requestdata];

}
#pragma mark - GETDataURL
-(void)requestdata
{
    mainstr = [NSString stringWithFormat:@"http://34.227.18.172/guru/web/api/data/livedata?email=iu@h.com"];
   [webservice executequery:mainstr strpremeter:nil withblock:^(NSData * dbdata, NSError *error) {
        NSLog(@"Data: %@", dbdata);
        if (dbdata!=nil)
        {
            NSDictionary *maindic = [NSJSONSerialization JSONObjectWithData:dbdata options:NSJSONReadingAllowFragments error:nil];
            NSLog(@"Response Data: %@", maindic);
            NSDictionary *dic1=[maindic objectForKey:@"message"];

            for (NSDictionary *dic in dic1)
            {
                [self.tableView reloadData];
                NSString *playerName=[dic objectForKey:@"player_name"];
                NSString *playerPhoto=[dic objectForKey:@"player_photo"];
                 NSString *playerPosition=[dic objectForKey:@"position"];
                 NSString *clubName=[dic objectForKey:@"club_name"];
                 NSString *playerPoints=[dic objectForKey:@"points"];
                NSString *priceChange=[dic objectForKey:@"price_change"];
                mainDic = [NSDictionary dictionaryWithObjectsAndKeys:playerName, player_name,playerPhoto, player_photo,playerPosition, position,clubName,club_name,playerPoints, points,priceChange,price_change,nil];
                [mainArray addObject:mainDic];

                [self.tableView reloadData];
                [player_name addObject:playerName];
                [player_photo addObject:playerPhoto];
                [position addObject:playerPosition];
                [club_name addObject:clubName];
                [points addObject:playerPoints];
                [price_change addObject:priceChange];




                NSLog(@"playerName : %@", playerName);
                 NSLog(@"playerPhoto : %@", playerPhoto);
                 NSLog(@"playerPosition : %@", playerPosition);
                 NSLog(@"clubName : %@", clubName);
                 NSLog(@"playerPoints : %@", playerPoints);
                 NSLog(@"priceChange : %@", priceChange);

                [self.tableView reloadData];
            }
            [self.tableView reloadData];






        }
       [self.tableView reloadData];
    }];
    [self.tableView reloadData];

}


#pragma mark - TableViewMethod
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 213;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44.f;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return player_name.count;

}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

   LiveScreenTableViewCell *cell;
     cell=[tableView dequeueReusableCellWithIdentifier:@"myCell"];
    if (cell==nil)
    {
        cell=[[LiveScreenTableViewCell alloc ]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"myCell"];



    }
     cell.player_Name.text= [player_name objectAtIndex:indexPath.row];


    cell.position.text=[position objectAtIndex:indexPath.row];
    cell.clubName.text=[club_name objectAtIndex:indexPath.row];
    cell.priceChange.text=[price_change objectAtIndex:indexPath.row];
    cell.points.text=[points objectAtIndex:indexPath.row];


    NSDictionary *tmpDict = [mainArray objectAtIndex:indexPath.row];

    NSURL *url = [NSURL URLWithString:[tmpDict objectForKey:player_photo]];
    [cell.player_Photo sd_setImageWithURL:url
                         placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    return cell;


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

图像未加载到UIImage中,我在做什么错, URL变为nil,这是什么问题,任何人都可以编写正确的代码以在tableView Cell中显示JSON图片。实际上,我对目标C还是陌生的 任何人都可以帮助我并指导我 UIIMAGE + TABLEVIEW CELL + JSON PARSING +目标C 感谢您的提前帮助。

0 个答案:

没有答案