2011-02-07 7 views
1

何らかの理由で私の最初の画面(つまりRootViewControllerから)でテーブルを表示できないというナビゲーションアプリケーションがあります。私は私の「のviewDidLoad」メソッドによって呼び出され、次の方法があります: `いくつかの作業を行いますRootViewControllerでテーブルを表示できません

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

` をして、メソッドを呼び出します。

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

このメソッドは、ANといくつかの作業を行いますNSArrayのは、宣言されたプロパティである「sortedArray」と呼ばれ、RootViewControllerで合成:

//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:)]; 

これは、上記の方法が終了する方法です。私はその後、私の "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; 

}

は、すべてが正常に見えます。私のコードを実行すると、NSArray sortedArrayにデータが含まれていることを明らかに示すNSLogステートメントがコンソールに出力されます。それでも、XCodeのiPhoneシミュレータでコードを実行すると、空のテーブルが表示されます。誰かが私が間違っているのを見ることができますか?

返信いただいたすべての方に、ありがとうございます。

答えて

0

tablebuilderをinterface builderのプロパティに接続しましたか?

また、並べ替えられた配列が変更された場合は、[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]が返されます。

関連する問題