重新加载UITableView

问题描述 投票:1回答:2

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

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

我有另一个名为qazxsw poi(qazxsw poi)的课程。这个类导入我的“Place.h”。

在我的DisplayPlaces我有这个代码:

UiViewController

在我的方法viewDidLoad我加载JSON URL并将结果放入Places *places = [[Places alloc]init]; [places.locationManager startUpdatingLocation]; [places LoadPlaces:places.locationManager.location]; [places.locationManager stopUpdatingLocation]; [places release]; 后我得到的地方并放入LoadPlaces并返回。

进入我的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; } ,但我无法刷新我的UiTableView。

我能做什么?

ios objective-c uitableview reload
2个回答
1
投票

将您的tableview ReturnPlaces: NSArray设置为您的财产并使用

[MyUiTableView reloadData]

如果你在tableView的任何方法内重新加载,只需使用

yourTableView

如果你在tableView方法之外重新加载,请使用

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

0
投票

您是否在tableView的实例上调用reloadData。换句话说,如果你有

[tableView reloadData];

然后重新加载它需要你打电话

[self.yourTableView reloadData];

MyUITableView *mytableView;
© www.soinside.com 2019 - 2024. All rights reserved.