English 中文(简体)
为什么我没有必要建造设计师和开工来利用这些变量?
原标题:Why don t I have to build setters & getters to use these variables?

When I m writing code inside the Cocoa Application I am able to get away with not using the @property "bla bla bla" and @synthesize ". . . "

并且我仍然想用我所宣称的变量做些什么。 例如。

IBOutlet NSTextField *textField;
IBOutlet NSTextView *viewField;

然后简单地将方法建设在这些变量以下。

-(IBAction)buttonPressed:(id)sender;
-(int)adding;

然后,我可以查阅一下当天的档案,我可以做这样的事情。

-(IBAction)buttonPressed:(id)sender {
int myVariable = [self adding];

[viewField insertText:[NSString stringWithFormat:@".... %i", myVariable]];

iii

-(int)adding {
    int myAge = [textField intValue];
    int myVariable = 100 - myAge;

    return myVariable;
iii

我拿不出为什么我能够这样做,而没有作出任何安排和安排;事先得到。

任何人都可以解释。 感谢。

Oh和另外一件事。

如果一个变量在申报方法中仅有效,那么我为什么能够这样做。

例如

-(int)myMethod {
int variableA = 50;

iii

-(int)myotherMethod  {
  int variableA + 100;

iii

回答是150。

母亲如何做 方法知道变量 a 等于50。 我认为,它们可以相互接触。

最佳回答

需要综合方法(植被和构造)才能从该类外获得实例变量。 该类别中的法典(例如,方法)可直接查阅实例变量。 这些规定适用于执行类别的任何法规。 范围是整个类别,而不仅仅是一类方法。

就业

问题回答

暂无回答




相关问题
Python: Binding method

In following example I am trying to bind a method object via types.MethodType(...). It does not seem to work. Any suggestions? Thanks in advance. import types class Base: def payload(self, *args)...

Invoking an instance method without invoking constructor

Let s say I have the following class which I am not allowed to change: public class C { public C() { CreateSideEffects(); } public void M() { DoSomethingUseful(); } } and I have to call M ...

Behaviour of final static method

I have been playing around with modifiers with static method and came across a weird behaviour. As we know, static methods cannot be overridden, as they are associated with class rather than instance....

Setting the Page-Title in .Net using C# from a Class

Question, How do i set the title of a page from a class. Is it even possible? I can and have set the page title from a page itself and a usercontrol. Can I, How Do I do this via a class using C# ....

how to drag in the animation in iphone application?

Iphone application is using the static co-ordinates to reach at some points in the application,which is based on the button event. But what i want is when i drag the item than it should reach at some ...

热门标签