我在许多视图控制器中单击按钮时显示自定义 UIView(类似于 UIAlertView)。因此,我已将该代码包含在 NSObject 类中。我必须将 UITableView 显示为此自定义视图的子视图,并且我的 UITableView 单元格之一包含倒数计时器。我能够显示 CustomView 和 UITableView。但是,我无法在这个 customView 中实现 NSTimer。
显示自定义视图的代码:
+(NSMutableDictionary *) printPopup:(UIView *)inputView {
int i=20;
UIView *myCustomView = [[UIView alloc] initWithFrame:CGRectMake(20, 100, 280, 250)];
[myCustomView setBackgroundColor:[UIColor colorWithRed:(247/255.0) green:(239/255.0) blue:(218/255.0) alpha:1]];
UITableView *dynamicTable=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 280, 250) style:UITableViewStylePlain];
dynamicTable.tag=55;
[myCustomView addSubview:dynamicTable];
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// [cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
[cancelButton setBackgroundImage:[UIImage imageNamed:@"Delete3.png"] forState:UIControlStateNormal];
[cancelButton setFrame:CGRectMake(250, 0, 30, 30)];
cancelButton.tag=i+7;
[myCustomView addSubview:cancelButton];
[inputView addSubview:myCustomView];
[UIView animateWithDuration:0.4f animations:^{
[myCustomView setAlpha:1.0f];
}];
NSMutableDictionary *returnedDic=[[NSMutableDictionary alloc]init];
[returnedDic setObject:dynamicTable forKey:@"Tableview"];
[returnedDic setObject:cancelButton forKey:@"cancelButton"];
return returnedDic;
}
+ (void)dismissCustomView:(UIButton *)sender
{
[UIView animateWithDuration:0.2f animations:^{
[sender.superview setAlpha:0.0f];
}completion:^(BOOL done){
[sender.superview removeFromSuperview];
}];
}
当我试图在这个 NSObject 类中实现 NSTimer 时,我收到以下错误:
instance variable accessed in class method
我必须在这个类中调用 NSTimer。有没有其他选择。
请建议。