何らかの理由で私の最初の画面(つまり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シミュレータでコードを実行すると、空のテーブルが表示されます。誰かが私が間違っているのを見ることができますか?
返信いただいたすべての方に、ありがとうございます。
お返事ありがとうございます。このコードブロックはどこに配置しますか(つまり、どの方法)?それはでしょうか:cellForRowAtIndexPathかそれとも:readRestaurantsFromDatabaseですか?あなたの助けをもう一度ありがとう。世話をする。 – syedfa
私の編集例を見てください。基本的には、tableViewに表示されているデータを変更するたびに、変更されたことをtableViewに伝える必要があります。 – deanWombourne
おかげさまでありがとうございました。あなたのソリューションは機能しました!世話をする – syedfa