无法理解iPhone视图布局

时间:2022-03-02 01:00:18

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/problems: 1) Why is it that my CityDetailView.xib looks like this in Interface Builder:

我有一个基于教程构建的iphone应用程序(针对不同的框架,所以我必须稍微修改一下)在同一个View上使用TabBar和NavigationBar,它还包含一个从SQLite数据库填充的UITable。我昨晚制作了它,当你在UITable中选择一个项目时,它被重定向到一个显示我的项目细节的视图(此时,只是一个城市名称)。我进去并试图修改DetailView ......并且我没有改变任何工作。所以我有一些问题/问题:1)为什么我的CityDetailView.xib在Interface Builder中看起来像这样:

alt text http://www.jamespwright.com/images/public/detailviewinterfacebuilder.jpg

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

替代文字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:

我是iPhone开发新手,所以我甚至不确定从哪里开始寻找这个问题。我知道TableViewController设置为CitiesTableViewController并且在我的didSelectRowAtIndexPath中的控制器代码中运行此代码:

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.

我将Interface Builder中的标签链接到Controller中的属性。我还将CityDetailView.xib类标识设置为CityDetailViewController,它具有正确声明的所有属性。有一点我无法弄清楚,如果我将CityDetailView.xib重命名为“CityDetailView.xib1”,程序仍然运行相同,但如果我改变[self.cityView.title = city.name]; to [self.cityView.title = @“Bob's Your Uncle!”];它显示程序内的变化。

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:

在一个完全无关的说明中,在我的TableView(我的第二个标签)上,我在底部有这个奇怪的栏,我不知道它是什么或如何摆脱它,我很确定它与NavigationController,但我不知道为什么或如何在那里。就是这个:

alt text http://www.jamespwright.com/images/public/tabandnavigationview.jpg

替代文字http://www.jamespwright.com/images/public/tabandnavigationview.jpg

Can anyone offer me any advice on these problems?

有人能就这些问题向我提出任何建议吗?

2 个解决方案

#1


1  

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)
  • 日期被搞砸了,你需要清理(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.

清洁绝对是第一个尝试。特别是如果你可以重命名XIB,一切仍然愉快地继续。

#2


0  

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.

最简单的解释是self.cityView.stateName和后续标签未在接口构建器中连接。控制器必须有一个连接到每个标签的插座,以便填充它。如果您向无法找到的对象发送消息,则Objective-C不会引发错误。

#1


1  

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)
  • 日期被搞砸了,你需要清理(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.

清洁绝对是第一个尝试。特别是如果你可以重命名XIB,一切仍然愉快地继续。

#2


0  

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.

最简单的解释是self.cityView.stateName和后续标签未在接口构建器中连接。控制器必须有一个连接到每个标签的插座,以便填充它。如果您向无法找到的对象发送消息,则Objective-C不会引发错误。