简体   繁体   English

目标c TableView单元格详细信息ViewController

[英]objective c TableView cell Detail ViewController

My viewDidLoad 我的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];
    }

}

i am getting data from this method : 我从这种方法获取数据:

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

}

for show data in UITableView 用于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;
}

for show detils data in a tableview after select a cell 在选择单元格后在表格视图中显示detils数据

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

    }
}

But it's now working . 但是现在正在工作。 can some help me to solve this ..Thanks in advance 可以帮我解决这个问题..谢谢

NSString *NewsImageName = details[@"featured_image"]; ,it is dictionary not a string!, you could delete that line. ,它是字典而不是字符串!,您可以删除该行。

[details valueForKey:@"featured_image"] it is string, but you are assigning it to NSURL directly. [details valueForKey:@"featured_image"]它是字符串,但是您直接将其分配给NSURL

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

replace it as follows 如下替换

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在目标C中将图像从主viewController设置为tableView单元格? - How to set image from main viewController to tableView cell in objective C? 从明细视图控制器返回后,在嵌入式TableView单元格中停止activityIndi​​cator - Stop activityIndicator in Embedded TableView Cell Upon Return From Detail ViewController (目标 C)TABLEVIEW 单元格标识符重要吗? - (OBJECTIVE C) Is TABLEVIEW CELL IDENTIFIER important? 从另一个ViewController的Objective-C重载TableView - Objective-c reload tableview from another viewcontroller 目标C:离开ViewController后停止加载TableView - objective C : Stop loading TableView after leaving ViewController 使用Objective-C从其他ViewController重新加载TableView - Reload TableView from different ViewController using Objective-C 将数据从Tableview传递回ViewController文本字段Objective-C - Pass data back from tableview to viewcontroller textfield Objective - C 将对象从tableview传递到其内部tableview单元格目标c - Pass an object from tableview to its inner tableview cell objective c 在另一个TableView中的TableView单元格的Objective-c PushView - Objective-c PushView for a cell of TableView in an other TableView 在自定义Tableview Cell中推送ViewController - Pushing the ViewController in customize Tableview Cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM