我有一個導航應用程序,由於某些原因,我不能在初始屏幕(即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