int alert()
{
//Alerting
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"0%" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(5, 5, 50.0F, 50.0F)];
UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[sampleButton setFrame:CGRectMake(0,5,60.0F, 40.0F)];
[sampleButton setBackgroundImage:[UIImage systemImageNamed:@"terminal.fill"] forState:UIControlStateNormal];
[sampleButton addTarget:[[MyObject alloc] init] action:@selector(showTerminal) forControlEvents:UIControlEventTouchDown];
[customView addSubview:sampleButton];
[alert.view addSubview:customView];
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
});
}
@implementation MyObject
-(void)showTerminal
{
NSLog(@"Terminal opened!");
}
@end
从另一个@实现调用函数时,如何使@ Select 器工作! 我已经try 过此代码,但该函数从不执行"[sampleButton addTarget:[[MyObject Alalc]init]action:@selector(ShowTerm)for ControlEvents:UIControlEventTouchDown];",有人能帮我修复它吗?或者告诉我一个不涉及使用视图控制器的解决方法!