2013-08-06 4 views
0

게시물 피드를로드하는 iOS 앱이 있습니다. 테이블 셀 텍스트 레이블은 post.content를 표시합니다. 게시물의 위치와 타임 스탬프를 표시하기 위해 detailTextLabel을 얻으려고합니다. 타임 스탬프는 작동하지만 위치는 좌표 (0.000, 0.000)를 반환합니다. 이 코드세부 텍스트 레이블 적절한 콘텐츠가 표시되지 않습니다.

- (void)configureCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
     Post *post = [self.posts objectAtIndex:indexPath.row]; 

cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.textLabel.numberOfLines = 0; 
    cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping; 
    cell.textLabel.text = post.content; 
    cell.detailTextLabel.textColor=[UIColor lightGrayColor]; 
    cell.detailTextLabel.font = [UIFont boldSystemFontOfSize:9]; 

     cell.detailTextLabel.text = [NSString stringWithFormat:@"posted on %@ at (%f, %f)", post.timestamp, (post.location.coordinate.latitude, post.location.coordinate.longitude)]; 
     } 

소인이 정확하고, 좌표는 아니다. 포스트 모델에는 CLLocation 속성이 있습니다. 는 내가 선언

static NSString * NSStringFromCoordinate(CLLocationCoordinate2D coordinate) { 
    return [ NSString stringWithFormat:@"(%f, %f)", coordinate.latitude, coordinate.longitude]; 
} 

내가 지금처럼 근처 게시물 가져 오기 :

+ (void)fetchNearbyPosts:(CLLocation *)location 
      withBlock:(void (^)(NSArray *posts, NSError *error))completionBlock 
{ 
    NSDictionary *parameters = @{ 
           @"lat": @(location.coordinate.latitude), 
           @"lng": @(location.coordinate.longitude) 
           }; 

을 그리고이 위치 사전이 모든 사이

NSDictionary *locationDictionary = [dictionary objectForKey:@"location"]; 
self.location = [[CLLocation alloc] initWithLatitude:[[locationDictionary valueForKey:@"lat"] doubleValue] longitude:[[locationDictionary valueForKey:@"lng"] doubleValue]]; 

와 JSON에서 업데이트 - 무엇을 방해하는 detailTextLabel이 적절한 좌표를 표시하지 않습니까? 나는 그것이 detailTextLabel 코드에서 뭔가라고 생각한다. 적절한 좌표 이름을 호출하지 않아 0을 반환한다. 사실 post.location.coordinate 섹션 전체를 삭제하면 레이블은 똑같은 것을 반환한다. 위치를 표현하는 여러 가지 방법을 시도했지만 대부분의 대안은 예외를 발생시키고 이것이 작동하지 않아야합니까? 아이디어가 있으십니까?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (!cell) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 

    [self configureCell:cell forRowAtIndexPath:indexPath]; 
    return cell; 
} 

그리고 이것은 실제 JSON입니다 - 경우에 당신이 내지도에 이상한 아무것도 볼 ...

[{"content":"Test","postid":1,"lat":"34.13327300486596","lng":"-118.1054221597022", "created_at":"2013-08-06T14:59:42Z"}] 
+1

tableView : cellForRowAtIndexPath : 메서드를 포함 할 수 있습니까? – akhalsa

+0

configureCell : forRowAtIndexPath에 post.location.coordinate.latitude 및 post.location.coordinate.longitude를 기록하여 올바른 값을 반환하는지 확인 했습니까? – rdelmar

+0

@akhalsa 위의 방법을 – grantvansant

답변

0
cell.detailTextLabel.text = [NSString stringWithFormat:@"posted on %@ at (%f, %f)", 
    post.timestamp, 
    (post.location.coordinate.latitude, post.location.coordinate.longitude)]; 

는 위도와 경도의 주위에 그 여분의 괄호 제거

cell.detailTextLabel.text = [NSString stringWithFormat:@"posted on %@ at (%f, %f)", 
    post.timestamp, 
    post.location.coordinate.latitude, 
    post.location.coordinate.longitude]; 
+0

여전히 (0.00, 0.00)이 문제가 다른 곳에서있을 수 있다고 생각합니다. 그러나 나는 혼란 스럽다. post.timestamp는 json 객체 "created_at"에서 매핑되며 완벽하게 작동합니다. 위의 위치를 ​​json 맵에 포함 시켰습니다. 올바르게 맵핑되지 않았습니다. json에서 표시되는 lat/lng가 반환되지 않으므로 가정합니다. 코드의 다른 부분에 아무것도 표시되어 있습니까? – grantvansant

관련 문제