iOS:向UITableView显示信息

时间:2014-07-24 09:09:16

标签: ios objective-c json uitableview nsmutablearray

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

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

但我不知道如何显示" status"在表格中:

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 =字典[@" status"];食谱或NSArray或......在桌子上展示

1 个答案:

答案 0 :(得分:0)

尝试在你的CellForRowAtIndexPathMethod做这样的事情

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

然后 只需将其用作

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