Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-02-2009, 03:38 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 4
Default 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.

SpecialtyListViewController.h
Code:
#import <UIKit/UIKit.h>

@class SpecialtyViewController;

@interface SpecialtyListViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
	IBOutlet UITableView *specialtyTableView;
	NSMutableArray *specialtyArray;
	NSString *selectedSpecialty;
}

@property (nonatomic, retain) UITableView *specialtyTableView;

@end
SpecialtyListViewController.m
Code:
#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: @"&amp;" 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.

Any ideas, comments, questions, thoughts?

Thanks in advance
-Justin

iPhoneOS 3.1.2
xcode 3.1.4
DevJustin is offline   Reply With Quote
Old 11-02-2009, 03:44 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Is there a XIB file? If so, make sure the IBOutlet is connected.

If not, you don't seem to be building the table in code anywhere. So the property would be nil.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 11-02-2009, 03:57 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 4
Default

There is no xib.

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.

-Justin
DevJustin is offline   Reply With Quote
Old 11-02-2009, 06:11 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

This:

Code:
@property (nonatomic, retain) UITableView *specialtyTableView;
Is basically just a placeholder. It does not actually create the table.

So somewhere in your code, possibly viewDidLoad, you'll need to do something like this:

Code:
UITableView *table = [[UITableView alloc] initWithStyle: ...];
[self setSpecialtyTableView: table];
[table release], table = nil;
I'm not seeing where what you have should be working at all, regardless of device vs. simulator.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 11-03-2009, 03:56 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 4
Default

Code:
- (void)viewDidLoad {
	// Populate table with specialities parsed from SOAP response
	specialtyArray = [[NSMutableArray alloc] init];
	
	SearchParameters *searchParameters = [SearchParameters sharedSearchParameters];
	specialtyArray = searchParameters.specialties;
	
	// Initialize selected variable
	selectedSpecialty = @"";
	
	UITableView *table = [[UITableView alloc] init];
	[self setSpecialtyTableView:table];
	table.delegate = self;
	table.dataSource = self;
	
	[super viewDidLoad];
	[table release];
}
So I made the above changes and now it wipes out all the previous pages as well.

While working thru the debugger further, I noticed that on the simulator it will make the calls to
Code:
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
but on the phone it doesn't make those calls. (Previous code or the newly modified code.

Thoughts?

I am thinking about just building a basic XIB and pushing things to it.

Thanks,
-Justin
DevJustin is offline   Reply With Quote
Old 11-03-2009, 04:21 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

You've got a leak with specialtyArray there, but that's probably not related.

No idea why a table would work in the simulator but not the device.

I'd vote for a XIB, yes.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 11-05-2009, 04:35 PM   #7 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 4
Default

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!
DevJustin is offline   Reply With Quote
Reply

Bookmarks

Tags
simulator, uitableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 256
19 members and 237 guests
14DEV, @sandris, ADY, ArtieFufkin10, bookesp, ckgni, Dani77, DarkAn, Desert Diva, HemiMG, iDifferent, jakerocheleau, JasonR, prchn4christ, Rudy, ryantcb, Speed, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:46 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0