我创建了一个UIButton的子类:
//
// DetailButton.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MyDetailButton : UIButton {
NSObject *annotation;
}
@property (nonatomic, retain) NSObject *annotation;
@end
//
// DetailButton.m
//
#import "MyDetailButton.h"
@implementation MyDetailButton
@synthesize annotation;
@end
Run Code Online (Sandbox Code Playgroud)
我想我可以通过执行以下操作创建此对象并设置注释对象:
MyDetailButton* rightButton = [MyDetailButton buttonWithType:UIButtonTypeDetailDisclosure];
rightButton.annotation = localAnnotation;
Run Code Online (Sandbox Code Playgroud)
localAnnotation是一个NSObject,但它实际上是一个MKAnnotation.我不明白为什么这不起作用,但在运行时我得到这个错误:
2010-05-27 10:37:29.214 DonorMapProto1[5241:207] *** -[UIButton annotation]: unrecognized selector sent to instance 0x445a190
2010-05-27 10:37:29.215 DonorMapProto1[5241:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIButton annotation]: unrecognized selector sent to instance 0x445a190'
Run Code Online (Sandbox Code Playgroud)
"
我不明白为什么它甚至会查看UIButton,因为我已经将其子类化了,所以应该查看MyDetailButton类来设置该注释属性.我错过了一些非常明显的东西.感觉就像:)
提前感谢您提供的任何帮助
罗斯
所以我有这个代码,我试图通过首先解决这个问题
class Lecturer (Person):
def lecture (self, stuff):
self.say(stuff + "- you should be taking notes")
Run Code Online (Sandbox Code Playgroud)
然后,我正在努力创建一个名为教授的课程,这个课程要求我这样做的代码
class Professor (Person):
def profess (self, stuff):
self.say("Its intuitively obvious that")
Run Code Online (Sandbox Code Playgroud)
然而,这里出现了一个问题,我需要将讲座定义为def,以便def将其称为它,这意味着它将声明的第一部分添加到结尾.
恩.X表示"直觉明显......不管怎么说 - 你应该做笔记"
我只是不知道如何让它调用它,你需要像Lecturer.say(自我,东西)或类似的东西,我的hw我自己学习python但是任何帮助将得到赞赏我自己继续努力.
我试图在子类UIScrollView中删除可移动的UIImageViews,以便我可以在UIScrollView中拖动它们.我将UISCrollView子类化并且删除行为正常,但是当我尝试拖动图像时,touchesMoved仅被评估一次.我的UIScrollView子类中的touchesMoved方法如下所示:
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
if (!self.dragging) {
[self.nextResponder touchesMoved: touches withEvent:event];
}else{
[super touchesEnded:touches withEvent:event];
}
}
Run Code Online (Sandbox Code Playgroud)
它应该在移动触摸过程中被连续调用.任何人都可以想到我的视图控制器中的touchesMoved方法只会被调用一次的原因吗?
我对如何在子类中创建方法感到困惑.我正用这个撞在砖墙上,甚至不确定如何说出这个问题.
import java.io.*;
public class A {
public double method1(double x, double y) { return 1.0; }
}
class B extends A {
//subclass method to be placed after this line
}
Run Code Online (Sandbox Code Playgroud)
public double method1(double x, double y) { ... }public int method1(double x, double y) { ... }public double method1(int x, int y) { .... }public int method1(double x, double y, double z) { ... }以下哪种方法在子类中是合法的,为什么?
给定一个类结构,如......
@interface SuperClassView : NSView @end
@interface SubClassedView : SuperClassView @property int aProp; @end
Run Code Online (Sandbox Code Playgroud)
如何SubClassedView从一个实例中实例化一个SuperClassView?
假设一个方法返回一个超类的实例SuperView....
SuperClassView *superInstance = [ViewFactory makeSuperClassView];
Run Code Online (Sandbox Code Playgroud)
但是我想得到一个子类 的实例SubClassedView?不可能简单地"施放"它......
SubClassedView *subClsInstance = (SubClassedView*)[ViewFactory makeSuperClassView];
Run Code Online (Sandbox Code Playgroud)
并且没有内置(或容易想象的实现)NSObject方法
self = [super initWithInstance:[superInstance copy]];`
Run Code Online (Sandbox Code Playgroud)
是将超类实例的所需属性复制到新实例化的子类对象的唯一方法,如...
SubClassedView *subClsInstance = SubClassedView.new;
for (NSString* someKey in @["frame",@"color",@"someOtherProperty])
[subClsInstance setValue:[superInstance valueForKey:someKey] forKey:someKey];
Run Code Online (Sandbox Code Playgroud)
或(添加在运行时调酒)子类'附加属性方法’(在这种情况下,setAProp:和aProp),以超实例(也投它向上)...
SubClassedView *subClsInstance = (SubClassedView*)[ViewFactory makeSuperClassView];
[subClsInstance addSwizzleMethod:@selector(setAProp:) viaSomeMagic:....];
[subClsInstance addSwizzleMethod:@selector(aProp) …Run Code Online (Sandbox Code Playgroud) 我有一些java代码:
class Protected{
int n = 1;
public Protected(){
System.out.println("Constructor of protected");
System.out.println("========================");
System.out.println("n = "+n);
System.out.println();
}
}
class Derived extends Protected{
Derived(){
System.out.println("Constructor of derived");
System.out.println("======================");
System.out.println("n = "+(n+1));
}
}
public class Demo{
public static void main(String args[]){
Derived ob2 = new Derived();
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出为:
constructor of protected
========================
n=1
constructor of Derived
========================
n=2
Run Code Online (Sandbox Code Playgroud)
这就是我要的:
constructor of Derived
========================
n=2
Run Code Online (Sandbox Code Playgroud) 让我先说我知道这是一个经常被问到的问题,我似乎无法找到与我一样的情景/问题的人.
我正在写一个音乐应用程序,我想出了一个我喜欢的用户界面.它需要一个具有特殊功能的按钮(过去可以通过自定义按钮类型实现),所以我决定创建一个UIButton子类.我在我的子类中使用了以下代码:
required init(coder aDecoder: NSCoder) {
self.activeState = false
self.activeAccidental = UIImageView()
super.init(coder: aDecoder)
self.layer.borderColor = UIColor(white:221/255, alpha: 1.0).CGColor
self.layer.borderWidth = 2.0
self.backgroundColor = UIColor.blackColor()
self.setTitleColor(UIColor.whiteColor(), forState: .Normal)
self.setTitle("Hello", forState: .Normal)
}
override func layoutSubviews() {
println(self.frame.origin.x)
self.activeAccidental = UIImageView(frame: CGRectMake(self.bounds.origin.x, self.bounds.origin.y, 20, 20))
self.activeAccidental.image = UIImage(named: "BMICalcIcon.png")
self.addSubview(activeAccidental)
}
Run Code Online (Sandbox Code Playgroud)
但是,当我向故事板添加一个按钮(并在字段中输入自定义类名称)时,无论是在显示的初始值设置中还是在故事板中的属性检查器中设置,我的标题都不可见.这是我在swift中的第一个重大项目,所以我不确定问题是什么.
ImageView移动到的代码initWithCoder
required init(coder aDecoder: NSCoder) {
self.activeState = false
self.activeAccidental = UIImageView()
super.init(coder: aDecoder)
self.activeAccidental = UIImageView(frame: CGRectMake(self.bounds.origin.x, self.bounds.origin.y, 20, 20))
self.activeAccidental.image = UIImage(named: …Run Code Online (Sandbox Code Playgroud) 我想初始化几个子类并将它们全部放入超类哺乳动物的数组中.使用此代码我得到错误:找不到添加(狼)的合适方法.我不知道我做错了什么,感谢任何帮助.
class gameRunner{
cow Cow = new cow();
wolf Wolf = new wolf();
ArrayList<mammal> mammalArray = new ArrayList<mammal>();
public gameRunner(){
mammalArray.add(Cow);
mammalArray.add(Wolf);
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
public class AClass {
public AClass() {
System.out.println("Constructor A");
}
}
public class BClass extends AClass{
public BClass(){
System.out.println("Constructor B");
}
}
public class Test {
public static void main(String[] args) {
BClass b = new BClass();
}
}
Run Code Online (Sandbox Code Playgroud)
我改变了代码,如下所示:
public class AClass {
public AClass() {
System.out.println("Constructor A");
}
}
public class BClass extends AClass{
public BClass(){
System.out.println("Constructor B");
}
}
public class Test {
public static void main(String[] args) {
BClass b = new AClass();
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作自己的Vector3类(3D矢量类),但我发现了一个小问题.我的目标是定义:
static const Vector3 zero = Vector3 (0.0, 0.0, 0.0);
static const Vector3 one = Vector3 (1.0, 1.0, 1.0);
Run Code Online (Sandbox Code Playgroud)
在Vector3类中,所以我可以通过以下方式访问它们:
Vector3::zero;
Vector3::one;
Run Code Online (Sandbox Code Playgroud)
但似乎(如果我理解这个问题)我不能在同一个类中声明一个类实例(就像Vector3定义中的Vector3),可能因为当我声明零和一时,Vector3本身的定义没有得出结论然而.你知道解决这个问题的任何解决方法吗?如果可能的话,我更喜欢不使用任何返回Vector3(0.0,0.0,0.0)或Vector3(1.0,1.0,1.0)的函数,而是使用静态const变量而无需额外的计算
subclass ×10
java ×4
class ×3
objective-c ×3
cocoa ×2
ios ×2
superclass ×2
uibutton ×2
arguments ×1
arraylist ×1
arrays ×1
c++ ×1
cocoa-touch ×1
constructor ×1
inheritance ×1
methods ×1
nsobject ×1
pointers ×1
python ×1
return-value ×1
swift ×1
templates ×1
touchesmoved ×1
uiscrollview ×1