繁体   English   中英

不会在其他类,Objective-C上调用方法

[英]Won't call on method in other class, Objective-C

我正在尝试为iOS学习Objective-C。 我目前正在关注iTunesU上的“编码”。 虽然我已经卡住了,因为我无法让我的控制器调用另一个类的方法。 找不到我做错了什么,并认为StackOverflow可能有解决方案!

方法“flipCardAtIndex”是不起作用的方法。 我已经使用nslog进行了调试,并从方法“flipCard”获得输出。 但是,当我为flipCardAtIndex实现时,我没有得到任何东西..所以我的猜测是它永远不会调用它...我已经使代码更短了所以它只是我觉得重要的部分,这是控制器:

#import "ViewController.h"
#import "PlayingCardDeck.h"
#import "CardMatchingGame.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *flipsLabel;
@property (nonatomic) int flipCount;
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *cardButtons;
@property (strong, nonatomic) CardMatchingGame *game;

@end

@implementation ViewController

- (CardMatchingGame *) game{
    if (_game) _game = [[CardMatchingGame alloc] initWithCardCount:[self.cardButtons     count]
                                                     usingDeck:[[PlayingCardDeck alloc] init]];
    return _game;
}

- (IBAction)flipCard:(UIButton *)sender {

[self.game flipCardAtIndex:[self.cardButtons indexOfObject:sender]];
self.flipCount++;
[self updateUI];

}

并实施:

- (void)flipCardAtIndex:(NSUInteger)index
{
    NSLog(@"ALL YOUR BASE ARE BELONG TO US");
    Card *card = [self cardAtIndex:index];
}

固定?

- (CardMatchingGame *) game{
    if (!_game) _game = [[CardMatchingGame alloc] initWithCardCount:[self.cardButtons        count] usingDeck:[[PlayingCardDeck alloc] init]];
    return _game;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM