我是 xcode 的新手,我有一个非常基本的问题。我一直在寻找几天来找出我的代码不起作用的原因。我想将变量从一个 Viewcontroller 传递到另一个控制器。
这是我的视图控制器:
//
// GameViewController.m
// Cartas
//
// Created by Pedro Lopes on 10/5/13.
// Copyright (c) 2013 Pedro Lopes. All rights reserved.
//
#import "GameViewController.h"
#import "Baralho.h"
@interface GameViewController ()
@property (nonatomic,strong) Baralho *card;
@property (weak, nonatomic) IBOutlet UILabel *flipLabel;
@property (weak, nonatomic) IBOutlet UILabel *cartasRestantes;
@property (nonatomic) int flipsCount;
@property int contador;
@end
@implementation GameViewController
- (Baralho *)card
{
if (_card == nil)
_card = [[Baralho alloc] init];
return _card;
}
- (IBAction)flipCard:(UIButton *)sender
{
if (!sender.selected)
{
NSString *temp1 = [[self card] matchCard:@"Just a Test"];
NSString *temp2 = self.card.drawRandomCard;
[sender setTitle:temp2 forState:UIControlStateSelected];
self.cartasRestantes.text = [NSString stringWithFormat:@"Cartas Restantes: %@",temp1];
}
sender.selected = !sender.isSelected;
self.flipsCount++;
self.flipLabel.text = [NSString stringWithFormat:@"Flips: %d",self.flipsCount];
}
@end
这是我的另一个控制器
//
// Baralho.m
// Cartas
//
// Created by Pedro Lopes on 10/6/13.
// Copyright (c) 2013 Pedro Lopes. All rights reserved.
//
#import "Baralho.h"
@interface Baralho()
@end
@implementation Baralho
- (NSString *)matchCard:(NSString *)teste
{
_matchCard = teste;
return _matchCard;
}
@end
问题出现在以下行:
NSString *temp1 = [[self card] matchCard:@"Just a Test"];
错误是: !'Baralho' 的 No Visible interface 声明选择器'matchcard'
如何将变量传递给另一个控制器?
谢谢,
佩德罗。