【问题标题】:Call a method and pass a variable to another controller调用方法并将变量传递给另一个控制器
【发布时间】:2013-11-10 19:08:39
【问题描述】:

我是 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"];

错误是: !No Visible interface for 'Baralho' 声明选择器'matchcard'

如何将变量传递给另一个控制器?

谢谢,

佩德罗。

【问题讨论】:

    标签: objective-c variables methods controller


    【解决方案1】:

    您需要确保 Barahlo.h 声明:

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

    【讨论】:

      猜你喜欢
      • 2012-09-12
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多