Iphone UIView中的UITableView和UIImage

Iphone UIView中的UITableView和UIImage,iphone,Iphone,我正在开发一个应用程序,目前有一个视图控制器(称为ViewControllerX)。MainWindow.xib文件包含以下内容: File's Owner UIApplication First Responder UIResponder AppX App Delegate myAppDelegate myViewControllerX myViewControllerX Window

我正在开发一个应用程序,目前有一个视图控制器(称为ViewControllerX)。MainWindow.xib文件包含以下内容:

File's Owner              UIApplication  
First Responder           UIResponder  
AppX App Delegate         myAppDelegate  
myViewControllerX         myViewControllerX  
Window                    UIWindow  
File's Owner              UIApplication  
First Responder           UIResponder  
MainView                  UIView
  Image View (image1.jpg) UIImage View (Inside MainView)
  Rounded Rect Button     UIButton (Inside MainView)
  Rounded Rect Button     UIButton (Inside MainView)
  Table View              UITableView  (Inside MainView)
@interface ViewControllerY : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
UITableView*  mTableView;
}

@property (nonatomic, retain) IBOutlet UITableView* mTableView;
当我在Interface Builder中查看MainWindow.xib时,它显示了从“myViewControllerX”加载的视图。此文件的myViewControllerX.xib文件包含以下内容:

File's Owner              UIApplication  
First Responder           UIResponder  
AppX App Delegate         myAppDelegate  
myViewControllerX         myViewControllerX  
Window                    UIWindow  
File's Owner              UIApplication  
First Responder           UIResponder  
MainView                  UIView
  Image View (image1.jpg) UIImage View (Inside MainView)
  Rounded Rect Button     UIButton (Inside MainView)
  Rounded Rect Button     UIButton (Inside MainView)
  Table View              UITableView  (Inside MainView)
@interface ViewControllerY : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
UITableView*  mTableView;
}

@property (nonatomic, retain) IBOutlet UITableView* mTableView;
在表视图中,我将Outlets设置为dataSource=File's Owner和Delegate=File's Owner。引用出口被设置为mTableView,它是使用XCode中的IBOutlet定义的。当我运行这个程序时,所有的工作都很好,表格也会被填充

当用户单击表视图中的某个项目时,我希望有一个新视图滑动到位,其中还包含一个表视图(基本上第一个视图控制器显示一个概览列表,当用户单击某个项目时,我希望它显示所选项目的详细信息)。在myViewControllerX.m文件中,我有以下代码:

- (void)tableView:(UITableView*)theTableView didSelectRowAtIndexPath:(NSIndexPath*)theIndexPath 
{
[self.navigationController pushViewController:self.mViewControllerY animated:YES];
}
我已创建了ViewControllerY,并具有以下文件:

ViewControllerY.xib、ViewControllerY.m和ViewControllerY.h

在ViewControllerY的.xib文件中,我有:

File's Owner              UIApplication  
First Responder           UIResponder  
Table View                UITableView
当我运行这个程序时,它可以工作(因此,Interface Builder中的代码和连接都可以)。问题是它接管了整个视图,而我希望它有一个图像(和其他UI对象)以及一个表视图。我尝试将ViewControllerY的UITableView更改为UIView类型,然后以与ViewControllerX类似的方式在UIView内部添加UIImageView和UITableView,但我无法让它工作,现在我不确定该怎么办!所以,我的问题是,我该如何实施这一点?我希望能够在Interface Builder中设置它,那么如何更改它以处理此问题?e、 如何连接数据源、委托和出口等

在此提前感谢您的帮助。我试过各种各样的方法,但似乎都没能奏效。我肯定我就快到了,肯定错过了一些非常明显的东西

祝你一切顺利
Dave

您的
UINavigationController
使用的内容视图或多或少完全覆盖了您的设备屏幕。此视图用于主视图。如果您要求该
UINavigationController
推送另一个视图,则他将使用该视图在ViewControllery视图中进行交换,该视图也覆盖了整个屏幕


要获得所需的行为,应创建第二个“嵌入式”导航控制器实例,该实例仅负责最初由表视图提供的部分。将您的表视图显示为主视图,然后让导航控制器将您的其他视图切换到屏幕的这一部分。

在后退一步并进一步挖掘后,我找到了答案

高层解释

ViewControllerY需要属于UIViewController类,而不是UITableViewController类。.h文件中的ViewControllerY:UIViewController定义应包括表视图委托和数据源协议。ViewControllerY的成员必须持有UITableView*-称之为mTableView,并应定义为IBOutlet

然后,表视图委托方法应使用self.mTableView访问表

在Interface Builder中,UIView对象需要有一个连接到文件所有者的出口“视图”,UIView中的表视图需要将dataSounce和委托设置为文件所有者,mTableView出口也需要连接到文件所有者

低级解释

在ViewControllerY.h中,执行以下操作:

File's Owner              UIApplication  
First Responder           UIResponder  
AppX App Delegate         myAppDelegate  
myViewControllerX         myViewControllerX  
Window                    UIWindow  
File's Owner              UIApplication  
First Responder           UIResponder  
MainView                  UIView
  Image View (image1.jpg) UIImage View (Inside MainView)
  Rounded Rect Button     UIButton (Inside MainView)
  Rounded Rect Button     UIButton (Inside MainView)
  Table View              UITableView  (Inside MainView)
@interface ViewControllerY : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
UITableView*  mTableView;
}

@property (nonatomic, retain) IBOutlet UITableView* mTableView;
(显然,您需要以正常方式定义和处理所有其他表视图方法

ViewControllerY.xib应包含以下内容:

File's Owner       ViewControllerY
First Responder    UIResponder
View               UIView
  Image View       UIImageView
  Table View       UITableView
控制从文件所有者拖动到视图并选择“视图”。 控件从表视图拖动到文件的所有者,然后选择数据源。 控件从表视图拖动到文件的所有者,然后选择Deligate。 控件从文件所有者拖动到表视图,然后选择mTableView

就这样!然后你可以在UIView中添加其他UI对象,并以正常的方式适当地将它们连接起来。我不确定这是否是唯一或最好的解决方案,但它是有效的,我很满意


希望这能帮助有相同或类似问题的人。在你掌握窍门之前,这有点让人困惑。

我没有真正理解这个答案,因此不确定它是否有效。但是,从最初发布以来,我做了更多的工作,现在有了一个似乎很好的答案。请参阅下面发布的我的答案。