IOS CS193p - 为什么将IBAction连接拖到.m文件而不是.h? [英] IOS CS193p - Why was the IBAction connection dragged to .m file and not to .h?

查看:126
本文介绍了IOS CS193p - 为什么将IBAction连接拖到.m文件而不是.h?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在斯坦福CS193p课程的计算器演示中,IBOutlet连接被从标签拖到头文件。但是,IBAction连接直接在.m文件中创建。我尝试阅读文档并在Google上搜索,但找不到背后的原因。

I noticed that in the calculator demo of Stanford CS193p course, the IBOutlet connection was dragged from the label to header file. However, the IBAction connection was directly created in the .m file. I tried reading through the documentation and searched on Google but couldn't find the reason behind this.

我认为IBAction digitPressed方法应该在头文件中声明为好吧(不应该是界面的一部分吗?)。

I would argue that IBAction digitPressed method should be declared in the header file as well (shouldn't it be part of the interface?).

我显然对Objective C很新(主要是用Java工作)所以我确信我失踪了一些基本的东西。

I am obviously fairly new to Objective C (mostly worked in Java) so I am sure I am missing something basic.

任何人都可以解释一下吗?

Can anyone please explain?

推荐答案

声明事物在类的头文件中使它们成为公共接口的一部分。这包括在视图控制器上定义的插座和操作。

Declaring things in a class's header file makes them part of the public interface. This includes outlets and actions defined on a view controller.

是否应该公开某些内容是一个设计问题。一个好的校长是:只有在必须的时候。有了ViewControllers的出口和行动,他们通常不必 - 因此也不应该 - 公开。

Whether something ought to be made public is a design question. A good principal is: only if it has to be. With ViewControllers outlets and actions, more often than not, they don't have to be - and therefore shouldn't be - public.

通常情况下你做的是一些人预先猜测公共接口应该包含什么,然后(如果你是一个整洁的开发人员)你在实现成熟时再看看并删除任何不必要的东西。

What usually happens is that you make some guesses up front about what the public interface should contain, then (if you're a tidy developer) you take a look again when the implementation is matured and remove anything inessential.

这篇关于IOS CS193p - 为什么将IBAction连接拖到.m文件而不是.h?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆