UIButton action not working ios(UIButton动作不起作用ios)
本文介绍了UIButton动作不起作用ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将 xcode 6.2 更新为 7 并添加:
I update xcode 6.2 to 7 and add :
self.window.rootViewController = [UIViewController new];
在 AppDelegate.m 中
in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//add in there
self.window.rootViewController = [UIViewController new];
ViewController2 *viewController = [[ViewController2 alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
navController.navigationBar.tintColor = [UIColor colorWithRed:0/255.0 green: 30.0/255.0 blue: 200.0/255.0 alpha:1];
[self.window addSubview:navController.view];
return YES;
}
但是现在
[button_Sinnup addTarget:self action:@selector(PLP) forControlEvents:UIControlEventTouchUpInside];
此代码在 ViewController2.m 中不起作用
this code not working in the ViewController2.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view setBackgroundColor:[UIColor blueColor]];
UIButton *button_Sinnup = [UIButton buttonWithType:UIButtonTypeCustom];
[button_Sinnup setTitle:@"" forState:UIControlStateNormal];
[button_Sinnup addTarget:self action:@selector(PLP) forControlEvents:UIControlEventTouchUpInside];
button_Sinnup.frame = CGRectMake(16, 76, 185, 45);
[button_Sinnup setBackgroundColor:[UIColor colorWithRed:224.0f/255.0f green:31.0f/255.0f blue:73.0f/255.0 alpha:0]];
[ button_Sinnup setBackgroundColor:[UIColor redColor]];
[self.view addSubview:button_Sinnup];
}
我无法调用方法 PLP
i can't call the method PLP
- (void)PLP{
ViewController2* svc=[[ViewController2 alloc]init];
[self presentViewController:svc animated:YES completion:nil];
}
推荐答案
你在添加导航控制器时出错了:替换:
You are wrong at adding navigation controller: replace:
[self.window addSubview:navController.view];
与
self.window.rootViewController = navController;
这篇关于UIButton动作不起作用ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:UIButton动作不起作用ios


猜你喜欢
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- UITextView 内容插图 2022-01-01
- URL编码Swift iOS 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01