게시물 피드를로드하는 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"}]
tableView : cellForRowAtIndexPath : 메서드를 포함 할 수 있습니까? – akhalsa
configureCell : forRowAtIndexPath에 post.location.coordinate.latitude 및 post.location.coordinate.longitude를 기록하여 올바른 값을 반환하는지 확인 했습니까? – rdelmar
@akhalsa 위의 방법을 – grantvansant