首页
学习
活动
专区
圈层
工具
发布

IB的问题
EN

Stack Overflow用户
提问于 2010-10-12 23:04:20
回答 1查看 124关注 0票数 0

这是我在SO上的第一篇文章,所以嗨!

我也是Xcode和Obj-C的新手,所以不要太苛刻。

我正在关注来自Standford University youtube.com/watch?v=L-FK1TrpUng的演示,由于某种原因,我遇到了一个错误。与其从头开始,我更愿意找出我哪里错了。

好了,开始吧。

我有两个视图控制器,我现在正在学习推送和弹出。

我的第一个视图控制器(firstViewController.h)标题:

代码语言:javascript
复制
    #import <UIKit/UIKit.h>       
@interface FirstViewController : UIViewController {
    }
     - (IBAction)pushViewController:(id)sender;
    @end

最初,这是在实现文件(firstViewController.m)中设置的,如下所示

代码语言:javascript
复制
#import "firstViewController.h"
    @implementation FirstViewController
    - (IBAction)pushViewController:(id)sender{
}

此时,使用IB时,我按ctrl键从“文件的所有者”拖动到“UIButton”并连接了“pushViewController”。

然而,在此过程中,我收到了某种错误,但我忽略了它。

现在我将第二个视图控制器添加到我的第一个ViewController.m中,如下所示;

代码语言:javascript
复制
#import "firstViewController.h"
#import "secondViewController.h"

@implementation FirstViewController

    - (IBAction)pushViewController:(id)sender{
     SecondViewController *secondViewController = [[SecondViewController alloc] init];
     secondViewController.title = @"Second"; 
     [self.navigationController pushViewController:secondViewController animated:YES];
     [secondViewController release];
    }

我之前收到的错误似乎以某种方式阻止了我从secondViewController笔尖中的textLabel中按ctrl键拖动

(secdeViewController.h)

代码语言:javascript
复制
#import "firstViewController.h"
#import "secondViewController.h"


@implementation FirstViewController
- (IBAction)pushViewController:(id)sender{
 SecondViewController *secondViewController = [[SecondViewController alloc] init];
 secondViewController.title = @"Second";
 [self.navigationController pushViewController:secondViewController animated:YES];
 [secondViewController release];
}

因此,我通过在firstViewController.xib中右键单击我的原始UIButton删除了它的引用。

现在我不能重新创建从‘文件的所有者’到‘UIButton’,'pushViewController‘网点的链接(它是一个网点还是一个动作?)也不会在我的secondViewControllers nib中创建从“文件所有者”到“UILabel”的链接。

有什么帮助吗?

如果任何人感兴趣,请在此处查看项目文件。http://zer-o-one.com/upload/files/PushPop.zip

非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-13 00:48:19

插座是将一个对象连接到另一个对象的路径。操作是在特定对象上为响应事件而调用的方法名称。传统上,Cocoa经常使用target/action进行通信,不过现在这部分已经被块取代了。

不管怎样,你的项目:

firstViewController.xib错误地认为其文件所有者是“firstViewController”类型的类。它实际上是'FirstViewController‘类型--像大多数编程语言一样,Objective-C对类名是区分大小写的。在界面生成器中,打开firstViewControlller.xib,选择“文件所有者”,打开检查器并转到“I”选项卡,然后更正顶部的类名。完成后,尝试切换到connections选项卡(箭头指向右侧的那个选项卡),您应该会看到它正确地找到了您的类和IBAction。然后,您应该能够控制拖动。

基本上,同样的评论也适用于secondViewController。

如果你很好奇,Objective-C与C++的不同之处在于,所有的类名在运行时都是已知的,并且可以从其名称的字符串版本实例化一个类。这就是XIB/NIB的加载方式。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3916046

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档