2011-06-23 183 views
1

我是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:'它就可以做到這一切。 –

回答

0

你是否在你的tableView的實例上調用reloadData。如果您有

MyUITableView *mytableView; 

然後重裝換句話說,它會要求你打電話

[mytableView reloadData]; 

[MyUITableView reloadData]; 
1

設置你的tableview yourTableView爲您的財產和使用

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

如果你正在爲的tableView任何方法裏面重裝,只要使用

[tableView reloadData]; 

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

[self.yourTableView reloadData];