我是xcode的新手,我有一个非常基本的问题。我一直在寻找几天来找出我的代码无效的原因。我想将一个变量从一个Viewcontroller传递给另一个控制器。
这是我的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'的可见界面声明选择器'matchcard'
如何将变量传递给另一个控制器?
感谢,
佩德罗。
答案 0 :(得分:1)
您需要确保Barahlo.h声明:
- (NSString *)matchCard:(NSString *)teste;