【发布时间】:2023-03-05 05:54:01
【问题描述】:
我在NewLabel.m 中创建了一个名为NewLabel 的UILabel 的子类,代码如下
+ (NewLabel*)addLabelIntoView:(UIView*)view
{
NewLabel *label = [[NewLabel alloc] init];
//some codes
[view addSubview:label];
[NSTimer scheduledTimerWithTimeInterval:1.0f target:view selector:@selector(callActionInVC) userInfo:nil repeats:NO];
return label;
}
还有一个UIViewController,代码在UIViewController.m
- (void)viewDidLoad {
[NewLabel addLabelIntoView:self.view]
}
- (void)callActionInVC {
//do some actions
}
我想在NewLabel.m中调用UIViewController.m的函数callActionInVC,在NewLabel.m中,target:view不对,应该改成什么?子类中 UIViewController 的目标是什么?
或者有什么想法可以提出这个需求?
【问题讨论】:
-
使用委托模式
-
设置
target: <Your ViewController> selector:@selector(<YourViewController.method>) -
@MahendraGP 非常感谢。
标签: ios objective-c uiviewcontroller uilabel