我有一个导航应用程序,由于某些原因,我不能在初始屏幕(即RootViewController)上查看我的表格。我有以下方法由我“的viewDidLoad”方法叫:'无法在RootViewController中查看表格
- (void) locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
` ,做一些工作,然后调用该方法:
- (void) readRestaurantsFromDatabase:(double)userLatitude
withUserLocation:(double)userLongitude{
这个方法做了一些工作,一个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;
}
对我来说,一切都看起来不错。当我运行我的代码时,我有NSLog语句输出到控制台,清楚地显示出NSArray sortedArray包含数据。然而,当我在XCode的iPhone模拟器上运行代码时,我得到一个空表。任何人都可以看到我做错了什么?
在此先感谢所有回复的人。
非常感谢您的及时回复。我在哪里放置这段代码(即哪种方法)?会是:cellForRowAtIndexPath或将它是:readRestaurantsFromDatabase?再次感谢你的帮助。保重。 – syedfa 2011-02-07 18:42:57