如何在iOS Attribute Inspector中指定两个线条标签(How to specify two line label in iOS Attribute Inspector)
我正在创建一个View(即我去了
New -> iOS -> User Interface -> View
)。 我希望在我的视图中有两行UILabel。 但是当我在Line one here this. \nAnd line 2
将标签的文本设置为第一行时Line one here this. \nAnd line 2
Line one here this. \nAnd line 2
,整个文字显示在一行。 即使我指定标签应该有两行。 我怎么做两行?I am creating a View (i.e. I went to
New -> iOS -> User Interface -> View
). I want to have a two line UILabel in my View. But when I set the label's text asLine one here this. \nAnd line 2
, the entire literal shows up in one line. Even though I specify that the label should have two lines. How do I make it two lines?
原文:https://stackoverflow.com/questions/26392740
最满意答案
只有方法才能
overridable
字段,字段只能隐藏或不隐藏。this
实际上是指当前的Object
,它在Parent#getName()
方法中是Parent#getName()
类型,这样它将获得在Parent
定义的变量名的值,或者可能是父类,而不是像Child
这样的子类。这是一个简单的代码片段,显示了这个想法:
Child child = new Child(); // Show the variable name of the class Child System.out.println(child.name); // Show the variable name of the class Parent which is what this.name // does in the getName method System.out.println(((Parent)child).name);
输出:
Child Parent
Fields are not
overridable
only methods are, the fields can only be hidden or not.this
actually refers to the currentObject
which is of typeParent
in the methodParent#getName()
such that it will get the value of the variable name defined inParent
or potentially a parent class but not in a sub class likeChild
.Here is a simple code snippet that shows the idea:
Child child = new Child(); // Show the variable name of the class Child System.out.println(child.name); // Show the variable name of the class Parent which is what this.name // does in the getName method System.out.println(((Parent)child).name);
Output:
Child Parent
相关问答
更多-
只有方法才能overridable字段,字段只能隐藏或不隐藏。 this实际上是指当前的Object ,它在Parent#getName()方法中是Parent#getName()类型,这样它将获得在Parent定义的变量名的值,或者可能是父类,而不是像Child这样的子类。 这是一个简单的代码片段,显示了这个想法: Child child = new Child(); // Show the variable name of the class Child System.out.println(child ...
-
处理父类对象列表时调用Child类的方法(Calling a Child class' method when processing a list of Parent class objects)[2022-11-12]
如果您的IsOfType()测试通过,您可以将(指向父对象的)对象转换为一个Child2对象并访问其特定的成员函数。 编辑:这取决于你的设计和你如何严格确保IsOfType()实现将给出正确的答案(即它也适用于当你在一个星期添加新的子类)。 取而代之的是使用内建的Typeid可能会更安全。 实现任何孩子在父母身上所能拥有的每种可能的方法都很困难,所以当方法在语义上特别适用于Child2类时,上传就可以了。 If your IsOfType() test passes, you can cast the (p ... -
从父类调用子方法(Call child method from parent class)[2022-05-02]
您只需调用子方法即可完成此操作,例如: if($_POST['condition'] === 'A') : $this->some_parent_function(); $this->child_1_action(); 但是,你应该避免这样做。 将调查放在父母中调用只存在于子类中的方法是非常糟糕的设计气味。 通过利用着名的设计模式或者仅仅通过更好地思考类层次结构,总有一种方法可以以更加结构化的方式进行。 你可以考虑的一个非常简单的解决方案是在父类中实现所有这些方法,作为no-ops; 每个 ... -
在创建Object时,您使用的是Super类的引用,但是您的对象是子类,因此在调用m1()方法时,将调用被覆盖的方法。 如果你想调用超类的方法,那么对象应该是超类。 如下: Parent parent=new Parent(); parent.m1(); 要么 你可以从子类调用超类m1()方法。 @Override public void m1() { super.m1(); System.out.println("Child method"); } 要不然 import j ...
-
@After public void tearDown() { String name = getClass().getName(); // use name as filename } @After public void tearDown() { String name = getClass().getName(); // use name as filename }
-
这是线程安全的懒惰单例初始化的常用习惯用法。 如果您可以拥有单例类,则委派给私有静态实例化类。 public class MySingleton{ private MySingleton(){ } public static MySingleton getInstance(){ return SingletonCreator.INSTANCE; } private static class SingletonCreator{ private st ...
-
在Child类中重写calculateCost 。 因此,当从Child调用super.toString()时, super.toString()中的super.toString()将是Child的calculateCost 。 你必须在Child类中显式地放置super.calculateCost()来调用Parent的calculateCost 。 calculateCost is overriden in the Child class. Therefore when super.toString() ...
-
我不确定这是否是一个有效或明智的事情。 在某些情况下,使用派生类来实现父类的功能是有效的。 是否有意义从Matrix派生出SquareMatrix是另一个考虑因素。 要知道这个问题的答案,你需要考虑你的设计,并概述Matrix所有类不变量和成员函数的前后条件,然后考虑SquareMatrix是否能满足它们。 I'm not sure if this a valid, or sensible thing to do. It is valid to use a derived class, to impleme ...
-
您遇到了切片问题 。 vector
.push_back() 复制其参数,因此它调用Parent::Parent(const Parent &) (即复制构造函数) * 。 这真的没有什么不同: Parent x[10]; x[0] = Parent(); x[1] = Child(); *或者它可能是Parent::operator=(const Parent &) ,即复制赋值。 我累了,我不记得它需要什么。 You are encountering the slicing probl ... -
父类方法public void aMethod(List
A)和子类方法是public void aMethod(String A) 。 两者都有不同的参数,因此它不是Method Overriding 。 但是在子类中,它可以被认为是Method Overloading 。 当您调用该方法时,您将传递list参数,并且只有与此签名匹配且与父类匹配的方法。 因此调用父类的方法。 方法覆盖 对于基类中的方法重写方法,子类必须具有相同的签名,即相同的名称和相同的参数 。 但是,子类中的方法可以 ...