-
29-09-2019 - |
题
这是我的第一篇文章,所以嗨!
我也是Xcode和obj-c的新手,所以不要太苛刻。
由于某种原因,我正在关注Standford University YouTube.com/watch?v = l-fk1trpung的演示。而不是从头开始,我宁愿弄清楚我出错的地方。
好的,所以去了。
我有两个视图控制器,目前我正在学习有关Push and Pop的信息。
我的第一个视图控制器(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 I CTRL从“文件的所有者”拖到“ uibutton”并连接了“ pushViewController”
但是,一路上我收到某种错误的地方,我忽略了这些错误。
现在,我将第二个视图控制器添加到我的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];
}
我以前收到的错误似乎以某种方式阻止了我从我的secondviewController nib中的textlabel拖动Ctrl
(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];
}
因此,我通过右键单击firstViewController.xib中的原始UIBUTTON从我的原始UIBUTTON中删除了引用。
现在,我无法将链接从“文件的所有者”重新创建到“ uibuttons”,“ pushViewController”出口(是插座还是一个操作?),也不是在我的secondviewControllers中创建从“文件所有者”到'uilabel中的链接'。
有帮助吗?
如果有人有兴趣,请在此处进行项目文件。 http://zer-o-one.com/upload/files/pushpop.zip
非常感激。
解决方案
插座是将一个对象连接到另一个对象的路径。操作是针对事件的特定对象上调用的方法名称。传统上,可可在传统上使用目标/动作进行交流,尽管现在这部分被块所取代。
无论如何,您的项目:
firstViewController.xib错误地认为其文件所有者是类型“ FirstViewController”类。它实际上是类型的“ FirstViewController” - 与大多数编程语言一样,Objective-C对班级名称敏感。在Interface Builder中,打开FirstViewControlller.xib,选择“文件的所有者”,打开检查器并转到“ I”选项卡,然后更正顶部的类名。完成此操作后,尝试切换到“连接”选项卡(箭头指向右侧的一个),您应该看到它正确找到了您的类和IBAction。然后,您应该能够控制阻力。
基本上,相同的评论适用于SecondViewController。
如果您很好奇,Objective-C与EG C ++有所不同,因为所有类名称在运行时都知道,并且可以从其名称的字符串版本实例化类。这就是XIB/NIBS加载的方式。