gpt4 book ai didi

ios - 重新加载 UITableView

转载 作者:行者123 更新时间:2023-11-29 13:48:02 25 4
gpt4 key购买 nike

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

我有一个名为 Places (NSObject) 的类,我在其中找到 Google 地点中的地点并返回一个 NSArray

我有另一个名为 DisplayPlaces (UiViewController) 的类。此类导入我的“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。

我能做什么?

最佳答案

将你的tableview yourTableView设置为你的属性并使用

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

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

[tableView reloadData];

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

[self.yourTableView reloadData];

关于ios - 重新加载 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6458411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com