user812612
user812612

Reputation: 399

Reload UITableView

I'm a new programmer in Objective-C and I have a terrible problem in my first application.

I have one class called Places (NSObject) where I found places in a Google places and return an NSArray.

I have another classe called DisplayPlaces (UiViewController). This class imports my "Place.h".

In my viewDidLoad I have this code:

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

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

[places release];

In my method LoadPlaces I load JSON URL and put a result in NSDictionary after I get only places and put in NSArray and return.

Into my Places I alloc my DisplayPlaces and call a method ReturnPlaces: NSArray to return places that I found.

- (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;
}

It all works.

My problem is:

In my ReturnPlaces: NSArray I call [MyUiTableView reloadData] but I can't refresh my UiTableView.

What can I do?

Upvotes: 1

Views: 1608

Answers (2)

Legolas
Legolas

Reputation: 12325

Set your tableview yourTableView as your property and use

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

if you are reloading inside any method for tableView, just use

[tableView reloadData];

if you are reloading outside your tableView methods, use

[self.yourTableView reloadData];

Upvotes: 1

Jamie
Jamie

Reputation: 5112

Are you calling reloadData on the instance of your tableView. In other words if you have

MyUITableView *mytableView;

then reloading it would require you call

[mytableView reloadData];

not

[MyUITableView reloadData];

Upvotes: 0

Related Questions