ios - objective c TableView cell Detail ViewController

标签 ios objective-c iphone uitableview

我的viewDidLoad

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

}

用于在 UITableView 中显示数据

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

选择单元格后在表格 View 中显示详细数据

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

    }
}

但它现在可以工作了。有人可以帮我解决这个问题吗..提前致谢

最佳答案

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

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

NSURL *imageUrl=[详细信息 valueForKey:@"featured_image"];

替换如下

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

关于ios - objective c TableView cell Detail ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33530644/

相关文章:

android - 在 android 中的 html 中显示相机 View ,然后拍摄照片

android - 如何在 Ionic\Cordova 中获取用户 IP 地址并检查用户是否在线

iOS - 绘制渐变 - Swift

objective-c - 我如何在 objc-appscript 中编写以下 rb-appscript ?

html - UIWebview:如何在 html 链接之前放置一个图标并在点击时突出显示

ios - UITableView tableHeaderView 使用自动布局高度太小

ios - 如何将当前位置坐标放入 google maps api(相机)

iphone - iOS 7 状态栏重叠 UI

iphone - iTunes 在实时应用程序中连接测试用户?

iphone - 检查是否在UIPinchGestureRecognizer中释放了捏