1

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?

3
  • did set the delegate for the tableview? Commented Jun 23, 2011 at 17:51
  • If you set breakpoints in numberOfRowsInSection: and cellForRowAtIndexPath: does the program reach them? If it doesn't you probably didn't set the delegate. If it does, are the outputs what you expect? (numberOfRowsInSection returns the right count etc.) Commented Jun 23, 2011 at 18:35
  • What's the property you're using for referencing the UITableView? Did you set it's data source and delegate? Also, nowadays using dequeueReusableCellWithIdentifier: and then checking if the cell is nil is obsolete, just use dequeueReusableCellWithIdentifier:forIndexPath: and it will do it all for you. Commented Mar 1, 2018 at 23:32

2 Answers 2

1

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];
Sign up to request clarification or add additional context in comments.

Comments

0

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];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.