UITableView does not exist when run on iPhone, but works fine in Simulator.
Hello everyone,
I am trying to take over an application that was contracted out by my company. We are on a tight deadline and I am new to all things Apple. (no one in the company develops for Apple so I have to turn outward)
to the problem.
I have a dynamically created UITableView and it works fine in the simulator but doesn't work at all when it is installed on the actual iPhone device.
#import "SpecialtyListViewController.h"
#import "SearchParameters.h"
#import "Query.h"
@implementation SpecialtyListViewController
@synthesize specialtyTableView;
- (void)viewDidLoad {
// Populate table with specialities parsed from SOAP response
specialtyArray = [[NSMutableArray alloc] init];
//problem here: the specialtyTableView seems to be unallocated. But the code works on the simulator.
SearchParameters *searchParameters = [SearchParameters sharedSearchParameters];
specialtyArray = searchParameters.specialties;
// Initialize selected variable
selectedSpecialty = @"";
[super viewDidLoad];
}
//
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [specialtyArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSString *cellValue = [specialtyArray objectAtIndex:indexPath.row];
NSString *decoded = [cellValue stringByReplacingOccurrencesOfString: @"&" withString: @"&"];
cell.textLabel.text = decoded;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// When a specialty is tapped, update the Query object with its value
// and return to parent view
selectedSpecialty = [specialtyArray objectAtIndex:indexPath.row];
if (selectedSpecialty == @"Search all specialties") {
selectedSpecialty = @"";
}
Query *query = [Query sharedQuery];
query.specialty = selectedSpecialty;
[query release];
[self.navigationController popViewControllerAnimated:TRUE];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
Query *query = [Query sharedQuery];
if (query.specialty==@"") {
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[specialtyTableView selectRowAtIndexPath:scrollIndexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
//[self selectRowAtIndexPath:scrollIndexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
[scrollIndexPath release];
}
[query release];
}
//...I removed a few of the completely boilerplate code.
- (void)dealloc {
[specialtyArray release];
[selectedSpecialty release];
[super dealloc];
}
the way its being called
Code:
-(IBAction)showSpecialties:(id)sender {
// Allocate and assign view controller when button is tapped
if (self.specialtyListViewController == nil) {
SpecialtyListViewController *specialtyList = [SpecialtyListViewController alloc];
self.specialtyListViewController = specialtyList;
[specialtyList release];
}
self.specialtyListViewController.title = @"Provider Specialty";
[self.navigationController pushViewController:self.specialtyListViewController animated:YES];
}
If anyone has a tutorial or something related to the way this code is being used it would be greatly appreciated. I have been hunting for weeks and I can't find a single tutorial that is near enough that I can make sense of why this works in the Sim but doesn't work on the device. I have been looking through the iPhone development resources: iPhone Dev Center: Table View Programming Guide for iPhone OS: Creating and Configuring a Table View but I can't find anything different enough.
In terms of building the table in code, what might that look like?
The contents of the specialtyArray (strings) should be the text of the table. Since it works in the simulator, I would have thought it was working correctly without discreetly assigning anything. Thus my confusion.
OK. I have had it tested by the person who built it originally and it works for them on several phones. I tested another phone here and it doesn't work so I have uninstalled XCode and iPhone SDK and started over. If that doesn't fix it I will build a XIB and work on the leak that you pointed out..assuming I can find it.
Sorry, while they say that it is really similar to C, I have to disagree after 6 years of C/C++ coding, this syntax is killing me. Must Learn Faster!