1

We're trying to pass information between two views in xcode. We pick up some information in one form and we would to show this information in the next view. We send the information, but we can't receive it in the second view and change the label text with the inforation we send. When we print NSLog(@"%@", campo); in Formulario.m return [UILabel copyWithZone:]: unrecognized selector

ClassCodigo.h:

@property (strong, nonatomic) IBOutlet UITextField *input_codigo;

ClassCodigo.m:

@implementation ClassCodigo
@synthesize input_codigo;

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

 if ([[segue identifier] isEqualToString:@"pasa_codigo"]) {

 Formulario *segundoView = (Formulario *)[segue destinationViewController];
 NSLog(@"%@", input_codigo.text); //debug per veure que retorna
 segundoView.campo = [input_codigo text];

 }


}

Formulario.h:

@property (strong, nonatomic) IBOutlet UILabel *labelCampo;
@property (nonatomic, strong) NSString *campo;

Formulario.m:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"%@", campo); //debug per veure que retorna

    self.labelCampo.text = campo;
}
Soft Line
  • 37
  • 1
  • 9
  • Your IBOutlet labelCampo should be weak and not strong according to Apple Documentation. "Outlets that you create will therefore typically be weak by default, because: Outlets that you create to, for example, subviews of a view controller’s view or a window controller’s window, are arbitrary references between objects that do not imply ownership." But i don't think that's your problem. From : https://developer.apple.com/library/ios/documentation/general/conceptual/CocoaEncyclopedia/Outlets/Outlets.html – Ali Abbas Jun 23 '14 at 12:03
  • @ali59a I'm not saying your wrong but it is always good thing to include a link to the documentation as well if you are going to reference something. And `Soft Line` What line does it crash on? Somewhere you have a property that thinks it is a `UILabel` and `UILabel` doesn't respond to `copyWithZone:` – Popeye Jun 23 '14 at 12:05
  • @Popeye I added the link to my comment. Thank you for your comment. – Ali Abbas Jun 23 '14 at 12:07
  • http://stackoverflow.com/a/10784876/2106820 – Arfan Mirza Aug 14 '14 at 21:15

1 Answers1

2

campo is declared NSString *, but at runtime, NSLog(@"%@", campo) causes [UILabel copyWithZone:]: unrecognized selector.

This means you are assigning a UILabel * object to a variable which expects NSString *. This is the root cause of your error.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117