2011-02-07 10 views
1

나는 일하고있는 탐색 앱을 사용하여 초기 화면 (즉, RootViewController)에서 내 테이블을 볼 수 없습니다. `다음 몇 가지 작업을 수행하고, RootViewController에서 테이블을 볼 수 없습니다.

- (void) locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *)newLocation 
     fromLocation:(CLLocation *)oldLocation { 

`

메소드 호출 :이 방법은 몇 가지 작업을 수행

- (void) readRestaurantsFromDatabase:(double)userLatitude 
       withUserLocation:(double)userLongitude{ 

을 내 "viewDidLoad에"방법에 의해 호출되는 다음과 같은 방법을

//compile a list of categories 
     NSMutableArray *categoryList = [[NSMutableArray alloc] init]; 
     [categoryList addObject:@"All Types"]; 

     for (Restaurant *restCat in restaurants){ 

      [categoryList addObject:restCat.category]; 
     } 


     //remove duplicates 
     NSArray *copy = [categoryList copy]; 
     NSInteger index = [copy count] - 1; 

     for (NSString *restCategory in [copy reverseObjectEnumerator]) { 

      if ([categoryList indexOfObject:restCategory inRange:NSMakeRange(0, index)] != NSNotFound) { 
       [categoryList removeObjectAtIndex:index]; 
      } 

      index--; 

     } 

     [copy release]; 

     //put list in alphabetical order 
     sortedArray = [categoryList sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; 

이 위의 방법이 종료하는 방법입니다 :있는 NSArray는 속성을 선언하고, RootViewController에서 합성이다 "sortedArray"를 불렀다. 그때 내 "cellForRowAtIndexPath"방법에 대해 다음 코드를 : 나에게

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

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell. 

NSString *cellValue = [sortedArray objectAtIndex:indexPath.row]; 
cell.textLabel.text = cellValue; 

return cell; 

}

이 모든 것이 잘 보인다. 코드를 실행하면 콘솔에 출력을 출력하는 NSLog 문이있어서 NSArray sortedArray에 데이터가 있음을 분명하게 나타냅니다. 그러나 Xcode에서 iPhone 시뮬레이터의 코드를 실행하면 빈 테이블이 생깁니다. 누구든지 내가 뭘 잘못하고 있는지 알 수 있니?

미리 답변 해 주신 모든 분들께 감사드립니다.

답변

0

인터페이스 builder의 속성에 tableView를 연결 했습니까?

또한 정렬 된 배열이 변경되면 [myTabelView reloadData];으로 전화하여 테이블을 새로 고침 할 수 있습니다. 정렬 된 배열을 변경할 때마다이 작업을 수행하십시오. 즉,

//put list in alphabetical order 
sortedArray = [categoryList sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; 

// The sorted array has changed, get the table view to refresh 
[myTabelView reloadData]; 
+0

신속한 답장을 보내 주셔서 감사합니다. 이 코드 블록은 어디에 배치합니까 (즉, 어떤 메소드)? 그것은 될 : cellForRowAtIndexPath 또는 될 것이라고 : readRestaurantsFromDatabase? 도와 줘서 고마워. 조심해. – syedfa

+0

예를 보려면 제 편집을보십시오. 기본적으로 tableView가 보여주고있는 데이터를 변경할 때마다 tableView가 변경되었음을 알릴 필요가 있습니다. – deanWombourne

+0

신속한 도움을 제공해 주셔서 감사합니다. 당신의 솔루션은 효과가있었습니다! 주의를 기울이십시오. – syedfa

0

tableView : numberOfRowsInSection :을 구현 했습니까?

[sortedArray count]가 반환됩니다.

0

numbersOfRowInSection을 기입하셨습니까?

참고로 왜 배열에 객체가 포함되어있을 때 추가를 건너 뛰지 않고 모든 것을 복사하고 나서 중복을 제거하는지 이해할 수 없습니다.

0

tableview 데이터 소스 속성을 다시 확인하십시오. UITableView에 대한 데이터 소스가 설정되지 않은 경우. 개체를 설정했는지 확인하고 개체가 - (NSInteger) tableView : numberOfRowsInSection : 메서드를 정의하는지 확인하십시오.

[sortedArray count]를 반환해야합니다.

관련 문제