【问题标题】:I am trying to display response of json in UITableViewCell but not working我正在尝试在 UITableViewCell 中显示 json 的响应但不工作
【发布时间】:2015-12-02 07:55:30
【问题描述】:

您好,我正在尝试显示此图像中的响应,但未显示,并且出现了一些错误,请帮助我

-(void)getCategories
{
    Service *srv=[[Service alloc]init];

    NSString *str=@"http://streamtvbox.com/site/api/matrix/";//?country_code=91&phone=9173140993&fingerprint=2222222222";
    NSString *method=@"channels";
    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];

    [srv postToURL:str withMethod:method andParams:dict completion:^(BOOL success, NSDictionary *responseObj)
    {
        NSLog(@"%@",responseObj);
        arrayCategories = [responseObj valueForKey:@"categories"];
     }];
 }


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return arrayCategories.count;
}

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

{
    static NSString *simpleTableIdentifier = @"ChannelCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
     }

     cell.textLabel.text = [[arrayCategories objectAtIndex:indexPath.row]valueForKey:@"categories"];

     return cell;
}

【问题讨论】:

  • 您何时何地调用方法“getCategories”?我不确定,但看起来你应该在“getCategories”方法的末尾重新加载 tableView。
  • responseObj 是数组还是字典?
  • @Birendra 请提供更多详细信息,关于响应结构,但这里缺少 reload tableview
  • 在 responseObj 中,“类别”键在哪里?

标签: ios objective-c json uitableview


【解决方案1】:

收到回复后请重新加载,

 [srv postToURL:str withMethod:method andParams:dict completion:^(BOOL success, NSDictionary *responseObj)
    {
        NSLog(@"%@",responseObj);
        arrayCategories = [responseObj valueForKey:@"categories"];
    [youTableView reloadDate];
     }];

【讨论】:

  • [__NSCFDictionary objectAtIndex:]:无法识别的选择器发送到实例
  • 显然您的 arrayCategories 对象不是数组,而是字典 - 但您尝试在 cellATRowForIndexPath 函数中将其作为数组访问...
  • @Birendra 请给我你的数组结构:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-12
  • 2019-05-08
  • 1970-01-01
  • 2018-08-08
  • 1970-01-01
  • 2020-01-21
相关资源
最近更新 更多