我是Objective-C中的新程序員,在第一個應用程序中遇到了一個可怕的問題。重新加載UITableView
我有一個叫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中的代表? – Aravindhan
如果您在'numberOfRowsInSection:'和'cellForRowAtIndexPath:'中設置了斷點,程序是否會到達它們?如果沒有,你可能沒有設置代表。如果是這樣,那麼你的期望值是多少? ('numberOfRowsInSection'返回正確的計數等) –
你用來引用'UITableView'的屬性是什麼?你是否設置了數據源和委託?此外,現在使用'dequeueReusableCellWithIdentifier:'然後檢查單元格是否爲'nil'已經過時了,只需使用'dequeueReusableCellWithIdentifier:forIndexPath:'它就可以做到這一切。 –