【问题标题】:Linking File's Owners and View Controller [iPhone SDK]链接文件的所有者和视图控制器 [iPhone SDK]
【发布时间】:2008-10-08 21:20:44
【问题描述】:

就目前而言,我似乎遇到了 iPhone SDK 2.1 的问题 能够在 ViewController 和 View 之间建立关系 窗户。就 Cocoa Touch 类而言,我继续前进并添加了一个 UIViewController 子类。我确保目标是 现有项目。之后我添加了一个用户界面 - >查看 西布。在UIViewController 中,我有一些直截了当的代码 从其他地方的示例代码中逐字复制/粘贴:

EditViewController.h:

@interface EditorViewController : UIViewController <UITextFieldDelegate> {
    UITextField *field;
}

@property(nonatomic, retain) IBOutlet UITextField *field;
@end

EditViewController.m

#import "EditorViewController.h"

@implementation EditorViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:
         (UIInterfaceOrientation)interfaceOrientation {
   // Return YES for supported orientations
  return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


- (void)dealloc {
   [super dealloc];
}


@end

如您所知,它没有多大作用。现在,当我单击我的新 xib 时, 使用EditorViewController 引用类标识,不自动完成 发生,这对我来说意味着它没有这样的意识 EditorViewClass。当我尝试从视图中控制+单击时 文件的所有者,我明白了。

在这个过程中,我有哪些可能的特质? 忽略不允许我将视图输出到控制器?

除了将项目名称作为目标检查之外,我还如何确保我的用户界面视图 XIB 与项目相关联?

【问题讨论】:

    标签: iphone cocoa xcode interface-builder


    【解决方案1】:

    (这似乎不是 iPhone 所特有的——对于任何平台来说,它都是一类普遍的问题。)

    尚不清楚这意味着什么: “现在,当我单击我的新 xib 并使用 EditorViewController 引用类标识时,不会发生自动完成,这对我来说意味着它没有对 EditorViewClass 的这种认识。”

    您的意思是您选择了文件的所有者并尝试将其类设置为 EditorViewController,但 Interface Builder 没有为您自动完成类名?

    如果是这种情况,xib文件是否与项目关联?

    其他不直接相关的点:

    最佳实践是现在将 IBOutlet 与属性关联:

    @interface EditorViewController : UIViewController
    {
        UITextField *field;
    }
    @property(nonatomic, retain) IBOutlet UITextField *field;
    @end
    

    您还应该释放dealloc中的文本字段:

    -(void)dealloc {
        [textField release];
        [super dealloc];
     }
    

    您的问题的格式使您很难看到您编写的代码。术语也很“奇怪”——outlet 不是动词:

    “在这个过程中,我忽略了哪些可能的特性不允许我将视图输出到控制器?” 你的意思是: “有什么我可能忽略的东西意味着我无法将控制器的视图出口连接到 Interface Builder 中的视图吗?”

    【讨论】:

      【解决方案2】:

      它应该像选择文件所有者并在班级框中输入班级名称一样简单(它应该自动完成并且也在下拉菜单中)。确保您没有尝试将类设置为视图本身。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-10-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-14
        相关资源
        最近更新 更多