Xcode按钮:有些工作,有些不工作?

时间:2015-05-04 20:37:45

标签: ios objective-c uibutton ibaction

我正在尝试为我的高级项目设计一个应用程序,因此对iOS编码来说相当新。我创建了一个.xib视图控制器,并在一些卡片图像上添加了许多按钮。另一个玩家的手上有一个大按钮,并在每个玩家自己的牌上切断较小的按钮。

我已经为每个按钮添加了UIAlertControllers,打算让弹出窗口允许玩家玩或丢弃自己的牌,或者发送一些关于其他玩家的信息。

对于其他玩家的按钮,警报弹出正常,但底牌的警告完全没有。我已经检查过它们都连接到IBActions,代码几乎与IS工作的按钮相同。有什么想法吗?

这一切都包含在gameViewController.m: btnTop正确执行其操作中,而btnBottom1 - btnBottom5则不执行任何操作。

- (IBAction)btnTop:(id)sender{
    NSLog(@"Top Button Pressed. Displaying AlertView.");
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Give Information" message:@"Would you like to give information about color or number?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *actionColor = [UIAlertAction actionWithTitle:@"Color" style:UIAlertActionStyleDefault
                                                        handler:^(UIAlertAction *action)
                                  {
                                      [self giveColorInfo];
                                  }];
    UIAlertAction *actionNumber = [UIAlertAction actionWithTitle:@"Number" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:actionColor];
    [alertController addAction:actionNumber];
    [alertController addAction:actionCancel];
    [self presentViewController:alertController animated:YES completion:nil];

}

- (IBAction)btnBottom1:(id)sender{
    NSLog(@"Bottom 1 Button Pressed. Displaying AlertController.");
    UIAlertController *alertController2 = [UIAlertController alertControllerWithTitle:@"Play or Discard Card 1" message:@"Would you like to play or discard?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *actionPlay = [UIAlertAction actionWithTitle:@"Play" 
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *action)
                             {
                                 [self playCard:1];
                             }];

    UIAlertAction *actionDiscard = [UIAlertAction actionWithTitle:@"Discard" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil];
    [alertController2 addAction:actionPlay];
    [alertController2 addAction:actionDiscard];
    [alertController2 addAction:actionCancel];
    [self presentViewController:alertController2 animated:YES completion:nil];
}

- (IBAction)btnBottom2:(id)sender {
    NSLog(@"Bottom 2 Button Pressed. Displaying AlertView.");
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Play or Discard Card 2" message:@"Would you like to play or discard?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *actionPlay = [UIAlertAction actionWithTitle:@"Play" 
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *action)
                             {
                                 [self playCard:2];
                             }];
    UIAlertAction *actionDiscard = [UIAlertAction actionWithTitle:@"Discard" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:actionPlay];
    [alertController addAction:actionDiscard];
    [alertController addAction:actionCancel];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (IBAction)btnBottom3:(id)sender {
    NSLog(@"Bottom 3 Button Pressed. Displaying AlertView.");
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Play or Discard Card 3" message:@"Would you like to play or discard?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *actionPlay = [UIAlertAction actionWithTitle:@"Play"  
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *action)
                             {
                                 [self playCard:3];
                             }];
    UIAlertAction *actionDiscard = [UIAlertAction actionWithTitle:@"Discard" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:actionPlay];
    [alertController addAction:actionDiscard];
    [alertController addAction:actionCancel];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (IBAction)btnBottom4:(id)sender {
    NSLog(@"Bottom 4 Button Pressed. Displaying AlertView.");
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Play or Discard Card 4" message:@"Would you like to play or discard?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *actionPlay = [UIAlertAction actionWithTitle:@"Play"  
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *action)
                             {
                                 [self playCard:4];
                             }];
    UIAlertAction *actionDiscard = [UIAlertAction actionWithTitle:@"Discard" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:actionPlay];
    [alertController addAction:actionDiscard];
    [alertController addAction:actionCancel];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (IBAction)btnBottom5:(id)sender {
    NSLog(@"Bottom 5 Button Pressed. Displaying AlertView.");
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Play or Discard Card 5" message:@"Would you like to play or discard?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *actionPlay = [UIAlertAction actionWithTitle:@"Play"  
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *action)
                             {
                                 [self playCard:5];
                             }];
    UIAlertAction *actionDiscard = [UIAlertAction actionWithTitle:@"Discard" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:actionPlay];
    [alertController addAction:actionDiscard];
    [alertController addAction:actionCancel];
    [self presentViewController:alertController animated:YES completion:nil];
}

0 个答案:

没有答案