好的,我有点困惑.
我有一个UIScrollView的子类,这是我尝试像UI元素一样水平滚动"表视图".UIScrollView本身设置它在内部使用的UIGestureRecognizers,它似乎将自己设置为那些UIGestureRecognizers的委托.我在我的水平表元素/单元格上也有自己的UIGestureRecognizer设置,我自己的类设置为我自己的UIGestureRecognizer的委托.由于我的类是UIScrollView的子类,在运行时,UIGcureRecognizer委托调用来到我的类,用于UIScrollView内置的UIGestureRecognizers和我自己的UIGestureRecognizers.有点像PITA,但我们可以通过传递我们不关心的东西来解决这个问题.
-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]])
return NO;
else
{
if ([super respondsToSelector:@selector(gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:)])
return [super gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer];
else
return NO;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是检查[super respondsToSelector:@selector()]返回YES,但是当我实际调用它时,return [super gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer];我得到以下异常
2012-08-31 12:02:06.156 MyApp [35875:707] - [MyAppHorizontalImageScroller gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]:无法识别的选择器发送到实例0x21dd50
我本以为应该表明
- [UIScrollView gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]
但那可能没问题.但问题是,它说它响应然后不响应.
另外两个UIGestureRecognizer委托例程使用此代码(显然是不同的选择器).
感谢您的任何见解.
delegates objective-c super uigesturerecognizer respondstoselector
我是swift的新手,我不明白如何初始化一个类.
成功在类定义中初始化为 false
if (succeeded && (time>1000)){
errormessage += ";connection slow"
}
Run Code Online (Sandbox Code Playgroud)
时间初始化为
time = data[3].toInt()
Run Code Online (Sandbox Code Playgroud)
数据在哪里
var data = split(raw_data) {$0 == ","}
Run Code Online (Sandbox Code Playgroud)
并且raw_data是一个字符串.
类定义:
class geocodeObject: NSObject {
Run Code Online (Sandbox Code Playgroud)
init 定义:
init(lat: String,long:String,userstate:String) {
Run Code Online (Sandbox Code Playgroud)
(没有任何类型的超级初始化)编辑:完整的代码切入方式
class geocodeObject: NSObject {
//A type to store the data from the Reverse Geocoding API
//Not a retriever
//Options
let API_KEY_TEXAS = "9e4797c018164fdcb9a95edf3b10ccfc"
let DEV_MODE = true
//Loading status
var succeeded = false
var errormessage = "Not Initalized" //Not nesscarilly a failure, …Run Code Online (Sandbox Code Playgroud) 考虑以下一组表达式:
class T {{
/*1*/ Object o = T.super; // error: '.' expected
/*2*/ o.toString();
}}
Run Code Online (Sandbox Code Playgroud)
尝试编译这将失败的行/*1*/出现错误:
error: '.' expected
o = T.super;
^
Run Code Online (Sandbox Code Playgroud)
使用OpenJDK 1.8.0(Ubuntu)或Oracle JDK 1.8(Windows)时.
但是,Eclipse 4.5.0(Mars) 编译它没有任何错误,它导致:
class T {
T();
0 aload_0 [this]
1 invokespecial java.lang.Object() [8] // super()
4 aload_0 [this]
5 astore_1 [o] // o = T.super
7 invokevirtual java.lang.Object.toString() : java.lang.String [10]
10 pop // ^-- o.toString()
11 return
}
Run Code Online (Sandbox Code Playgroud)
从中您可以看到/*1*/ …
说我有以下课程:
class Foo {
protected void method() {}
}
class Bar extends Foo {
}
Run Code Online (Sandbox Code Playgroud)
此时,从类Bar,我可以通过method()两种方式访问:
super.method();this.method();从我看来,他们似乎执行相同的行动.在这种情况下,这两者之间是否存在差异?是否有首选版本可供使用?
使用super是有道理的,因为它method()是超类的一部分.this我认为使用也很有道理,因为Bar将继承Foo类的属性,因此method(),对吧?
我想创建一个namedtuple代表短位域中的各个标志的代码.我正在尝试将其子类化,以便在创建元组之前解压缩位域.但是,我目前的尝试不起作用:
class Status(collections.namedtuple("Status", "started checking start_after_check checked error paused queued loaded")):
__slots__ = ()
def __new__(cls, status):
super(cls).__new__(cls, status & 1, status & 2, status & 4, status & 8, status & 16, status & 32, status & 64, status & 128)
Run Code Online (Sandbox Code Playgroud)
现在,我的经验super()是有限的,我的经验__new__实际上是不存在的,所以我不太清楚该怎么做(对我来说)神秘的错误TypeError: super.__new__(Status): Status is not a subtype of super.谷歌搜索和挖掘文档并没有产生什么启发.
救命?
我正在使用PowerMock,我想知道如何保持子类的所有行为,但是存根super调用可能被子进程覆盖.
说我有这个班:
public class A {
public String someMethod() {
return "I don't want to see this value";
}
}
Run Code Online (Sandbox Code Playgroud)
和一个子类:
public class B extends A {
@Override
public String someMethod() {
return super.someMethod() + ", but I want to see this one";
}
}
Run Code Online (Sandbox Code Playgroud)
如何将呼叫存根到super.someMethod()?
我试过了
@Test
public void test() {
B spy = PowerMockito.spy(new B());
PowerMockito.doReturn("value").when((A)spy).someMethod();
assertEquals("value, but I want to see this one", spi.someMethod());
}
Run Code Online (Sandbox Code Playgroud) 在许多Android方法中,尤其是构造函数和重写方法,您应该甚至必须使用super()调用父类方法.当您使用Eclipse Source> Override/Implement Methods ...时,您可以从包含TODO标签的模板中获取代码,如下所示:
public MyCanvas(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
}
Run Code Online (Sandbox Code Playgroud)
我不太了解超类在每种情况下的作用,所以我总是在// TODO标签的确切位置插入我的代码.在这个例子中,我会在构造函数中的代码之前和onDraw()中的代码之后调用super().
我是否可以始终在生成的代码中依赖这些代码插入位置?调用super()时是否有简单的规则/解释?
我试图在块内的超类上调用一个方法.为了避免保留周期,我需要对super的弱引用.我如何获得对超级的弱引用?
[self somethingWithCompletion:^(){
[super doStuff];
}];
Run Code Online (Sandbox Code Playgroud)
我尝试了以下但是给出了编译错误.
__weak MySuperClass *superReference = super;
Run Code Online (Sandbox Code Playgroud) 在Raymond Hettinger 在PyCon 2015上的演讲" 超级考虑超级发言 "中,他解释了super在多重继承环境中使用Python 的优势.这是雷蒙德在演讲中使用的一个例子:
class DoughFactory(object):
def get_dough(self):
return 'insecticide treated wheat dough'
class Pizza(DoughFactory):
def order_pizza(self, *toppings):
print('Getting dough')
dough = super().get_dough()
print('Making pie with %s' % dough)
for topping in toppings:
print('Adding: %s' % topping)
class OrganicDoughFactory(DoughFactory):
def get_dough(self):
return 'pure untreated wheat dough'
class OrganicPizza(Pizza, OrganicDoughFactory):
pass
if __name__ == '__main__':
OrganicPizza().order_pizza('Sausage', 'Mushroom')
Run Code Online (Sandbox Code Playgroud)
有人在台下问雷蒙德有关使用的差异self.get_dough(),而不是super().get_dough().我对Raymond的简要回答并不是很了解,但我编写了这个例子的两个实现来看看差异.两种情况的输出相同:
Getting dough
Making pie with pure untreated wheat dough
Adding: Sausage
Adding: …Run Code Online (Sandbox Code Playgroud) 我怎么会叫一个Random从java.util.Random成supertype constructor?
例如
Random rand = new Random();
int randomValue = rand.nextInt(10) + 5;
public Something()
{
super(randomValue);
//Other Things
}
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时,编译器说我" 在调用randomValue之前无法引用supertype constructor".
super ×10
java ×4
eclipse ×2
objective-c ×2
python ×2
adt ×1
android ×1
class ×1
compilation ×1
delegates ×1
extends ×1
inheritance ×1
java-8 ×1
jls ×1
namedtuple ×1
new-operator ×1
overriding ×1
powermock ×1
random ×1
self ×1
stub ×1
swift ×1
this ×1