2013-10-30 36 views
0

我是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'

我該如何將變量傳遞給另一個控制器?

謝謝,

佩德羅。

回答

1

你需要確保Barahlo.h聲明:

- (NSString *)matchCard:(NSString *)teste; 
+0

非常感謝的答案!有效。 –

相關問題