【发布时间】:2011-02-07 12:59:37
【问题描述】:
我正在开发一个导航应用程序,由于某种原因,它不允许我在初始屏幕上查看我的表格(即从 RootViewController)。我的“viewDidLoad”方法调用了以下方法:`
- (void) locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
` 它做了一些工作,然后调用方法:
- (void) readRestaurantsFromDatabase:(double)userLatitude
withUserLocation:(double)userLongitude{
此方法对名为“sortedArray”的 NSArray 做了一些工作,它是在 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 模拟器上运行代码时,我得到一个空表。谁能看到我做错了什么?
提前感谢所有回复的人。
【问题讨论】:
标签: iphone objective-c cocoa-touch