UIButton 操作无效 ios
UIButton action not working ios
我将 xcode 6.2 更新为 7 并添加:
self.window.rootViewController = [UIViewController new];
在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
中不起作用
- (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
- (void)PLP{
ViewController2* svc=[[ViewController2 alloc]init];
[self presentViewController:svc animated:YES completion:nil];
}
您添加导航控制器的方式有误:
替换:
[self.window addSubview:navController.view];
和
self.window.rootViewController = navController;
我将 xcode 6.2 更新为 7 并添加:
self.window.rootViewController = [UIViewController new];
在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
中不起作用- (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
- (void)PLP{
ViewController2* svc=[[ViewController2 alloc]init];
[self presentViewController:svc animated:YES completion:nil];
}
您添加导航控制器的方式有误: 替换:
[self.window addSubview:navController.view];
和
self.window.rootViewController = navController;