objective c TableView单元格详细信息ViewController

时间:2015-11-04 19:43:46

标签: ios objective-c iphone uitableview

我的- (void)viewDidLoad { [super viewDidLoad]; appdataModel = [AppDataModel getInstance]; appdataModel.newsApiUrl = homePagesUrl; self.view.backgroundColor = [UIColor whiteColor]; NSString *path = [[NSBundle mainBundle] pathForResource:@"contacts" ofType:@"plist"]; contactsArray = [NSArray arrayWithContentsOfFile :path]; [self GetHomePageData]; /**** for left side menu ***/ SWRevealViewController *revealViewController = self.revealViewController; if ( revealViewController ) { [self.sideBarButton setTarget: self.revealViewController]; [self.sideBarButton setAction: @selector( revealToggle: )]; [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; } }

-(void)GetHomePageData{

   // url_to_load = homePagesNews;

    NSString *urlString   = [NSString stringWithFormat:@"%@",newsApiUrl];
    NSURL *url            = [[NSURL alloc]initWithString:urlString];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLResponse *response;
    NSData *GETReply      = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
    res = [NSJSONSerialization JSONObjectWithData:GETReply options:NSJSONReadingMutableLeaves|| NSJSONReadingMutableContainers error:nil];

}

我从这个方法获取数据:

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

    static NSString *cellIdentifier =@"Cell";
    CustomCell *customCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    details = res[indexPath.row];

    NSString *titleNews = details[@"title"];
    NSString *newsDateTime = details[@"datetime"];
    NSString *NewsImageName = details[@"featured_image"];

    //UIImage *image = [UIImage imageNamed:NewsImageName ];
   // UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:NewsImageName]]];

    customCell.customFirstNameLabel.text = titleNews;
    customCell.customLastnameLabel.text = newsDateTime;
    //customCell.customImageView.image =image;

    NSURL *imageUrl=[details valueForKey:@"featured_image"];

    [customCell.customImageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"no_image.png"]];
    //[tableView reloadData];

    return customCell;
}

用于UITableView中的节目数据

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if ([segue.identifier isEqualToString:@"detailSegue"]) {
    //s NSIndexPath *path = Nil;
     NSString *titleString  = Nil;

    NSIndexPath *path = [self.tableView indexPathForSelectedRow];
    titleString = [res objectAtIndex:path.row];
    [[segue destinationViewController] setTitle:titleString];

    }
}

用于在选择单元格后的表格视图中显示detils数据

app.js

但它现在正在运作。可以帮助我解决这个问题..提前谢谢

1 个答案:

答案 0 :(得分:1)

NSString *NewsImageName = details[@"featured_image"];,它是字典而不是字符串!,你可以删除该行。

[details valueForKey:@"featured_image"]它是字符串,但您直接将其分配给NSURL

NSURL *imageUrl=[details valueForKey:@"featured_image"];

将其替换如下

NSURL* imageUrl= [NSURL URLWithString:[details valueForKey:@"featured_image"]];
相关问题