【问题标题】:iOS: show info to UITableViewiOS:向 UITableView 显示信息
【发布时间】:2014-07-24 09:09:16
【问题描述】:

我有一张带有不同注释的地图,我从 json 和服务器获得了这些信息,我可以在地图上显示我的信息状态,我也想在我的表格中显示它,我的表格实现是正确的,当我使用这个数组,我可以将所有这些信息显示到我的表中:

 recipes = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full 
Breakfast", @"Hamburger", @"Ham and Egg Sandwich", nil];

但我不知道如何在表格中显示“状态”:

newAnnotation = [[MyAnnotation alloc] init];
newAnnotation.subtitle = dictionary[@"company"];
newAnnotation.status = dictionary[@"status"];



 - (void)viewDidLoad
{
[super viewDidLoad];

 //  recipes = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full 
Breakfast", @"Hamburger", @"Ham and Egg Sandwich", nil];

_mapView.delegate = self;

[ApiManager fetchCoordinates:^(id result) {


    newAnnotations = [NSMutableArray array];
    CLLocationCoordinate2D location;
    NSArray *array=(NSArray*)result;


    for (NSDictionary *dictionary in array)
    {

        // create the annotation
        MyAnnotation *newAnnotation;


        newAnnotation = [[MyAnnotation alloc] init];
        newAnnotation.subtitle = dictionary[@"company"];
        newAnnotation.status = dictionary[@"status"];



        [newAnnotations addObject:newAnnotation];
    }

    [self.mapView addAnnotations:newAnnotations];

 } failure:^(NSError *error) {

 }];
 }

感谢回答部分中的任何代码,提前致谢!

我的 cellForRowAtIndexPath 方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
 *)indexPath
{
static NSString *simpleTableIdentifier = @"Item";

UITableViewCell *cell = [tableView 
dequeueReusableCellWithIdentifier:simpleTableIdentifier];

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


cell.textLabel.text = [recipes objectAtIndex:indexPath.row];
return cell;
}

更新:

我想添加这个 newAnnotation.status = dictionary[@"status"];到食谱或任何 NSArray 或...在桌子上显示它

【问题讨论】:

  • recipesstatus是什么关系?
  • @Paulw11 什么都没有,recipes 是 NSArray 并且状态位于此处 newAnnotation.status = dictionary[@"status"];并将 newAnnotation 添加到 [newAnnotations addObject:newAnnotation];因为 newAnnotations 是 NSMutableArray
  • 如果没有关系,那么如何在表格中显示状态?你想要自己的行中的状态吗?作为页眉还是页脚?显示在每一行?
  • @Paulw11 只想将其显示为单元格 textLabel,cell.textLabel.text = [recipes objectAtIndex:indexPath.row];
  • @Paulw11 所有这些信息都位于 newAnnotations 中,它是一个 NSMutableArray,我怎样才能使用这个 NSMutableArray 并显示所有信息?

标签: ios objective-c json uitableview nsmutablearray


【解决方案1】:

尝试在您的 CellForRowAtIndexPathMethod 中执行类似的操作

MyAnnotation *newAnnotation=[newAnnotations objectAtIndex:indexpath.row];

那么 把它当作

cell.textLabel.text=[NSString stringWithFormat:@"%@",newAnnotaion.Status];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 2021-12-31
    • 2020-10-11
    • 2021-06-11
    • 1970-01-01
    • 2015-07-17
    相关资源
    最近更新 更多