重新加载UITableView

问题描述:

我是Objective-C中的新程序员,在第一个应用程序中遇到了一个可怕的问题。重新加载UITableView

我有一个叫PlacesNSObject)的课,我在Google的地方找到了地方,并返回NSArray

我有另一种叫做DisplayPlacesUiViewController)的类别。这个类导入我的“Place.h”。

在我viewDidLoad我有这样的代码:

Places *places = [[Places alloc]init]; 

[places.locationManager startUpdatingLocation]; 
[places LoadPlaces:places.locationManager.location]; 
[places.locationManager stopUpdatingLocation]; 

[places release]; 

在我的方法LoadPlaces我加载JSON URL,并把结果在NSDictionary后,我得到唯一的地方,并把在NSArray和回报。

进入我的Places我分配我的DisplayPlaces并调用方法ReturnPlaces: NSArray返回找到的位置。

- (void)ReturnPlaces:(NSArray *)locais{ 
    placesArray = locais; 
    [self.UITableView reloadData]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return [placesArray count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *CellIndentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier]; 

    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIndentifier] autorelease]; 
    } 

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    cell.textLabel.text = [placesArray objectAtIndex:indexPath.row]; 
    return cell; 
} 

这一切正常。

我的问题是:

在我ReturnPlaces: NSArray我打电话[MyUiTableView reloadData]但我无法刷新我的UITableView。

我该怎么办?

+0

并设置了tableview中的代表? – Aravindhan

+0

如果您在'numberOfRowsInSection:'和'cellForRowAtIndexPath:'中设置了断点,程序是否会到达它们?如果没有,你可能没有设置代表。如果是这样,那么你的期望值是多少? ('numberOfRowsInSection'返回正确的计数等) –

+0

你用来引用'UITableView'的属性是什么?你是否设置了数据源和委托?此外,现在使用'dequeueReusableCellWithIdentifier:'然后检查单元格是否为'nil'已经过时了,只需使用'dequeueReusableCellWithIdentifier:forIndexPath:'它就可以做到这一切。 –

你是否在你的tableView的实例上调用reloadData。如果您有

MyUITableView *mytableView; 

然后重装换句话说,它会要求你打电话

[mytableView reloadData]; 

[MyUITableView reloadData]; 

设置你的tableview yourTableView为您的财产和使用

self.yourTableView = tableView; // for assigning the tableView contents to your property 

如果你正在为的tableView任何方法里面重装,只要使用

[tableView reloadData]; 

如果你重装的tableView方法外,使用

[self.yourTableView reloadData];