我从他的 UIViewController 访问视图方法时遇到问题。我两周前才开始在 xcode 中编程,我必须修改其他人制作的程序。
UIView 在 UIViewController 的 .xib 中的 interface builder 中拖放,并通过 initWithFrame 和 drawRect 方法进行初始化。此视图包含一个 NSTimer,当用户单击导航栏的按钮关闭时,我需要停止它。
所以我在 UIViewController 中有一个 IBAction,它在按下按钮关闭时被激活。这个方法应该启动 UIView 的方法之一,但它不起作用。Xcode 未检测到错误或警告,但 UIView 的代码从未运行。当我启动应用程序时,一切正常,但这个。
UIView.h:
@interface Clock3D : UIView {
...
NSTimer *timer;
NSTimer *timerS;
}
...
@property (retain, nonatomic) NSTimer *timer;
@property(保留,非原子) NSTimer *timerS;
...
-(无效)完成测试;
@结尾
UIView.m:
@implementation Clock3D
@synthesize timer, timerS, ...
...
-(void) doneTest{NSLog(@"arret timerS");
[定时器无效];
NSLog(@"arret 计时器");
[定时器无效];}
UIViewController.h:
导入“Clock3D.h”
@类时钟3D;
@interface Popup360 : UIViewController {
...
Clock3D *clock3D;
}
...
@property(retain, nonatomic) IBOutlet Clock3D *clock3D; ...
-(IBAction)完成;@结尾
UIViewController.m:
@implementation Popup360
@synthesize ...,clock3D;-(IBAction) done{
[clock3D doneTest];
[自我dismissModalViewControllerAnimated:是];
}
所以命令 [clock3D doneTest] 不起作用(来自 doneTest 的 NSLog 永远不会出现在日志中)但是命令 [self dismissModalViewControllerAnimated:YES]; 作品。
谢谢您的答复。