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?
numberOfRowsInSection:andcellForRowAtIndexPath: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? (numberOfRowsInSectionreturns the right count etc.)UITableView? Did you set it's data source and delegate? Also, nowadays usingdequeueReusableCellWithIdentifier:and then checking if the cell isnilis obsolete, just usedequeueReusableCellWithIdentifier:forIndexPath:and it will do it all for you.