gpt4 book ai didi

ios - objective c TableView cell Detail ViewController

转载 作者:行者123 更新时间:2023-11-29 01:30:20 25 4
gpt4 key购买 nike

我的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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com