ios - 不会调用其他类中的方法,Objective-C

标签 ios objective-c debugging

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

方法“flipCardAtIndex”是不起作用的方法。我已经使用 nslog 进行了调试,并从方法“flipCard”中得到了一个输出。但是当我为 FlipCardAtIndex 执行实现时,我什么也没有得到。所以我的猜测是它永远不会调用它...
我将代码缩短了一些,所以它只是我认为重要的部分,这是 Controller :

#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;
}

关于ios - 不会调用其他类中的方法,Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14738901/

相关文章:

ios - UIKit 和 GCD 线程安全

ios - 为什么 UITextView 在调整大小后在错误的框架中绘制文本?

ios - 纹理图集动画之间平滑切换

Delphi XE 项目 'Run Parameters' 设置不会在 session 之间持续存在

c - 使用 dbx 转储结构

debugging - 无法从存储 "C:\Users\aleja\.android\debug.keystore": Detect premature EOF 读取 key AndroidDebugKey

iOS 本地化搞乱了 UI

objective-c - 常量推断为类型 '()' ,这可能是意外的 - 在 Swift 中替换 dispatch_once

iphone - 在 UIImageView 周围设置边框

ios - 从客户端增加角标(Badge)计数而不是从有效负载接收计数