我在UILabel
中创建了一个名为NewLabel
NewLabel.m
的子类,代码如下
+ (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
}
我想在callActionInVC
中调用UIViewController.m
的{{1}}函数,而在NewLabel.m
中,NewLabel.m
是不对的,我应该改变什么?什么是子类中UIViewController的目标?
或者有什么想法可以满足这种需求吗?
答案 0 :(得分:0)
[NSTimer scheduledTimerWithTimeInterval:1.0f target:view selector:@selector(callActionInVC) userInfo:nil repeats:NO];
错误
[NSTimer scheduledTimerWithTimeInterval:1.0f target:<your controller> selector:@selector(callActionInVC) userInfo:nil repeats:NO];
您应该将target设置为控制器。
- (UIViewController *)fy_parentController{
UIResponder *responder = [self nextResponder];
while (responder) {
if ([responder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)responder;
}
responder = [responder nextResponder];
}
return nil;
}
您可能需要创建category才能获得控制器。
[NSTimer scheduledTimerWithTimeInterval:1.0f target:view.fy_parentController selector:@selector(callActionInVC) userInfo:nil repeats:NO];
最终代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Smoke Test" verbose="2" preserve-order="true">
<parameter name="baseUrl" value="https:test.com"/>
<test name="Smoke_Firefox">
<parameter name="browser" value="firefox"/>
<classes>
<class name="test.TestLogin">
<methods>
<include name="test_login"/>
<include name="test_logout"/>
</methods>
</class>
</classes>
</test>
<test name="Smoke_Chrome">
<parameter name="browser" value="chrome"/>
<classes>
<class name="test.TestLogin">
<methods>
<include name="test_login"/>
<include name="test_logout"/>
</methods>
</class>
</classes>
</test>
<test name="Smoke_IE">
<parameter name="browser" value="ie"/>
<classes>
<class name="test.TestLogin">
<methods>
<include name="test_login"/>
<include name="test_logout"/>
</methods>
</class>
</classes>
</test>
</suite>