Can't understand iPhone view layout
I have an iphone app that I built based off a tutorial (for a different framework so I had to modify things a bit) that uses a TabBar and a NavigationBar on the same View that also contains a UITable populated from an SQLite db. I built it last night and when you select an item in the UITable it was redirecting to a view that displayed the detail of my item (at that point, just a city name). I went in and tried to modify that DetailView...and nothing I change works. So I have a few questions/probl开发者_JAVA技巧ems: 1) Why is it that my CityDetailView.xib looks like this in Interface Builder:
alt text http://www.jamespwright.com/images/public/detailviewinterfacebuilder.jpg
But looks like this when the app is run:
alt text http://www.jamespwright.com/images/public/wrongdetailview.jpg
I am new to iPhone development, so I'm not even sure where to begin looking for this problem. I know that the TableViewController is set to CitiesTableViewController and within that controller code in my didSelectRowAtIndexPath I run this code:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
City *city = (City *)[appDelegate.cities objectAtIndex:indexPath.row];
// Initialize a new CityDetailView if there isn't one already
if (self.cityView == nil) {
CityDetailViewController *viewController = [[CityDetailViewController alloc] initWithNibName:@"CityDetailViewController" bundle:[NSBundle mainBundle]];
self.cityView = viewController;
[viewController release];
}
[appDelegate.citiesNavController pushViewController:cityView animated:YES];
self.cityView.city = city;
self.cityView.title = city.name;
[self.cityView.cityName setText:city.name];
[self.cityView.stateName setText:city.state];
[self.cityView.population setText:city.population];
And I have the labels linked up in Interface Builder to the properties in the Controller. I also have the CityDetailView.xib class identity set to CityDetailViewController which has all the properties correctly declared. One thing I can't figure out, if I rename CityDetailView.xib to "CityDetailView.xib1" the program still runs the same, but if I change [self.cityView.title = city.name]; to [self.cityView.title = @"Bob's Your Uncle!"]; it displays that change within the program.
On a completely unrelated note, on my TableView (my 2nd tab) I have this odd bar at the bottom that I don't know what it is or how to get rid of it, I'm pretty sure it has to do with the NavigationController but I don't know why or how it's there. It is this one:
alt text http://www.jamespwright.com/images/public/tabandnavigationview.jpg
Can anyone offer me any advice on these problems?
When "nothing happens" when you change source files, there are usually only a few things you're doing:
- Dates are screwed up somewhere and you need to clean (Build → Clean)
- You're editing the wrong file
- You're building the wrong target
- No, seriously, you're editing the wrong file, or building the wrong target
Cleaning is definitely the first thing to try. Especially if you can rename the XIB and everything still cheerfully goes on.
The simplest explanation is that self.cityView.stateName
and the subsequent labels are not hooked up in interface builder. The controller must have a hooked up outlet to each label in order to populate it. Objective-C won't raise an error if you send a message to an object it can't find.
精彩评论