IB 问题

发布于 2024-09-26 23:44:29 字数 2115 浏览 9 评论 0原文

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

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

我正在关注斯坦福大学的演示 youtube.com/watch?v=L-FK1TrpUng 由于某种原因我遇到了错误。与其从头开始,我更愿意找出我哪里出了问题。

好的,就这样吧。

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

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

    #import <UIKit/UIKit.h>       
@interface FirstViewController : UIViewController {
    }
     - (IBAction)pushViewController:(id)sender;
    @end

然后最初这是在实现文件(firstViewController.m)中设置的,就像这样

#import "firstViewController.h"
    @implementation FirstViewController
    - (IBAction)pushViewController:(id)sender{
}

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

然而,在途中的某个地方我收到了某种错误,但我忽略了它

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

#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];
    }

我之前收到的错误似乎以某种方式阻止我从 secondaryViewController 笔尖

(secondeViewController.h)

#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];
}

中的 textLabel 进行 ctrl 拖动,因此我通过在firstViewController.xib 中右键单击原始 UIButton 来删除引用。

现在我无法重新创建从“文件所有者”到“UIButtons”、“pushViewController”出口的链接(它是出口还是操作?),也无法在我的 secondaryViewControllers 笔尖中创建从“文件所有者”到“UILabel”的链接'。

有什么帮助吗?

如果有人感兴趣的话,可以在这里找到项目文件。 http://zer-o-one.com/upload/files/PushPop.zip 。

非常感谢

This is my first post on SO, so hi!

I'm new to Xcode and Obj-C too so don't be too harsh.

I am following the demo from Standford University youtube.com/watch?v=L-FK1TrpUng
For some reason i've hit an error. Rather than starting from scratch i'd prefer to figure out where I have gone wrong.

Ok so here goes.

I have two view controllers and i'm currently learning about push and pop.

My first view controllers (firstViewController.h) header:

    #import <UIKit/UIKit.h>       
@interface FirstViewController : UIViewController {
    }
     - (IBAction)pushViewController:(id)sender;
    @end

Then initially this was set up in the implementation file (firstViewController.m), like this

#import "firstViewController.h"
    @implementation FirstViewController
    - (IBAction)pushViewController:(id)sender{
}

At this point with IB I ctrl dragged from 'File's owner' to a 'UIButton' and connected 'pushViewController'

However, somewhere along the way I received somekind of error, which I ignored.

Now I have my second view controller added into my firstViewController.m like this;

#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];
    }

The error that I received previously seemed to somehow stop me from ctrl dragging from a textLabel in my secondViewController nib

(secondeViewController.h)

#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];
}

So i removed the references from my original UIButton via right clicking on it in the firstViewController.xib.

Now I cannot recreate the link from 'File's Owner' to the 'UIButtons', 'pushViewController' outlet (is it an outlet or is it an action?) nor create the link in my secondViewControllers nib from 'File's Owner' to the 'UILabel'.

Any help?

Project files here if anyone is interested. http://zer-o-one.com/upload/files/PushPop.zip

Much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风夜微凉 2024-10-03 23:44:29

出口是将一个对象连接到另一个对象的路径。操作是在特定对象上调用以响应事件的方法名称。 Cocoa 传统上大量使用目标/动作来进行通信,尽管现在这部分被块所取代。

无论如何,您的项目:

firstViewController.xib 错误地认为其文件所有者是“firstViewController”类型的类。它实际上是“FirstViewController”类型——与大多数编程语言一样,Objective-C 的类名区分大小写。在 Interface Builder 中,打开firstViewController.xib,选择“文件所有者”,打开检查器并转到“i”选项卡,然后更正顶部的类名称。完成此操作后,尝试切换到连接选项卡(箭头指向右侧的选项卡),您应该会看到它已正确找到您的类和 IBAction。然后您应该能够控制拖动。

基本上相同的评论适用于 secondaryViewController。

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

An outlet is a path that connects one object to another. An action is a method name that is called on a particular object in response to an event. Cocoa traditionally uses target/action quite a lot for communicating, though this is now being partly displaced by blocks.

Anyway, your project:

The firstViewController.xib incorrectly thinks that its file owner is a class of type 'firstViewController'. It's actually of type 'FirstViewController' — like most programming languages, Objective-C is case sensitive for class names. In Interface Builder, open firstViewControlller.xib, select 'File's Owner', open the inspector and head to the 'i' tab, then correct the class name at the top. When you've done that, try switching to the connections tab (the one with the arrow pointing to the right) and you should see that it's correctly found your class and your IBAction. You should then be able to control drag.

Basically the same comment applies to secondViewController.

In case you're curious, Objective-C differs from e.g. C++ in that all class names are known at runtime and it's possible to instantiate a class from the string version of its name. That's how XIBs/NIBs are loaded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文