【发布时间】:2011-04-27 17:22:51
【问题描述】:
我有两个 .m 文件。第一个是主要代码,第二个是 UIImageView 的子类,以便我可以检测触摸。
在主 .m 文件中,我添加了一个进度条和一个 customimageview 两个滚动视图的子视图。
我需要的是,当用户触摸 customimageview 时,进度条会向上移动并且双击会减少 [注意:customimageview 必须在第二个 .m 中识别其触摸,因为它们位于必须处理滚动视图和其他控件]
在主 .m 文件中,我有两种方法:
- (void)pumpsingletap {
progbm.progress +=0.1;
}
- (void)pumpdoubletap {
progbm.progress -=0.1;
}
然后在子类 uiimageview 我有:
//inside touches method
if ([touch view].tag == 555) {
NSLog(@"pump touched");
switch ([allTouches count]) {
case 1: {
switch ([touch tapCount]) {
//---single tap---
case 1: {
NSLog(@"single pump touch");
[self performSelector:@selector(pumpsingletap) withObject:nil afterDelay:.4];
} break;
//---double tap---
case 2: {
NSLog(@"double pump touch");
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(pumpsingletap) object:nil];
[self performSelector:@selector(pumpdoubletap) withObject:nil afterDelay:.4];
} break;
}
}
}
}
所以 NSlog 出现了,所以触摸识别不是问题。但是 performSelector 倒下了。由于 customimageview pumpingletap 不起作用。
那么我如何调用子类中的方法。
//更新//
所以我在我的子类中添加了以下代码
mainMethod* callingMethod = [[mainMethod alloc] init];
[callingMethod performSelector:@selector(pumpsingletap) withObject:nil afterDelay:.4];
然后在我用于 pumpingletap 的主要方法中,我将其更改为:
- (void)pumpsingletap {
NSLog(@"single pump method called");
progbm.progress +=0.1;
}
出现了调用单泵方法的 NSLog,但进度条 progbm - 没有移动。所以我已经解决了我的呼叫问题 - 现在只需要弄清楚为什么进度条没有移动!
【问题讨论】:
-
确保您的进度条已在界面生成器中连接
标签: iphone class methods touch subclass