0

please help me to resolve this issue

i have a view controller in a navigation stack named firstviewcontroller

FirstViewController.h

@class ImperialPickerController;
@class FractionPickerController;
@class MetricPickerController;

@interface FirstViewController : UIViewController {

    UIView *pickerViewContainer;

    ImperialPickerController *ImperialPickerController;
    FractionPickerController *FractionPickerController;
    MetricPickerController *MetricPickerController;

    UIView *ImperialPickerViewContainer;
    UIView *FractionPickerViewContainer;
    UIView *MetricPickerViewContainer;

    UISegmentedControl *segmentedControl;

    NSInteger selectedUnit;
}

@property(nonatomic,retain) IBOutlet UIView *pickerViewContainer;

@property(nonatomic,retain) IBOutlet UIView *ImperialPickerViewContainer;
@property(nonatomic,retain) IBOutlet UIView *FractionPickerViewContainer;
@property(nonatomic,retain) IBOutlet UIView *MetricPickerViewContainer;

@property(nonatomic,retain) IBOutlet ImperialPickerController *ImperialPickerController;
@property(nonatomic,retain) IBOutlet FractionPickerController *FractionPickerController;
@property(nonatomic,retain) IBOutlet MetricPickerController *MetricPickerController;

@property(nonatomic,retain) IBOutlet UISegmentedControl *segmentedControl;

-(IBAction)toggleUnit;

@end

FirstViewController.m

@implementation FirstViewController

@synthesize ImperialPickerController;
@synthesize FractionPickerController;
@synthesize MetricPickerController;
@synthesize ImperialPickerViewContainer;
@synthesize FractionPickerViewContainer;
@synthesize MetricPickerViewContainer;
@synthesize pickerViewContainer;
@synthesize segmentedControl;

define METRIC_INDEX 0
define IMPERIAL_INDEX 1
define FRACTION_INDEX 2



-(IBAction)toggleUnit
{
    selectedUnit = [segmentedControl selectedSegmentIndex];

    if (selectedUnit == METRIC_INDEX)
    {
        [MetricPickerController updateLabel1];
    }

}
@end

MetricPickerController.h

@interface MetricPickerController : NSObject <UIPickerViewDataSource,UIPickerViewDelegate> {

    UIPickerView *pickerView;
    UILabel *label;
}
@property(nonatomic,retain)UIPickerView *pickerView;
@property(nonatomic,retain)UILabel *label;

-(void)updateLabel1;

@end

MetricPickerController.m

import "MetricPickerController.h"

@implementation MetricPickerController

@synthesize pickerView;
@synthesize label;


-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component

{
    return 10;
}

-(void)updateLabel1
{
    label.text = @"test"
}

the problem is that i get an error message on compiling here in the firstviewcontroller

-(IBAction)toggleUnit
{
    selectedUnit = [segmentedControl selectedSegmentIndex];

    if (selectedUnit == METRIC_INDEX)
    {
        [MetricPickerController updateLabel1]; <<<<< (MetricPickerController might not respond to +updateLabel1)!!
also if i click the toggle in IB xcode will crash with sigbart error 
    }

can anyone please help and advise what i have done wrong i think i have everything hooked up properly so i guess this is to do with my method declaration somehow

i know the code is incomplete at this stage but its driving me crazy trying to get rid of this error and i hope you can appreciate that i am just a learner

}

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
superllanboy
  • 607
  • 2
  • 6
  • 18
  • 1
    See Adrian's answer below. I'd suggest a good naming scheme would be to use a lower-case first letter for instance variables and upper case for class names which will help with this in future. – Nick Bull Jun 28 '11 at 08:31
  • @Nick Bull 100% with you. Naming is so important, and really helps reducing bugs. – Eiko Jun 28 '11 at 09:11

1 Answers1

4

The problem is that updateLabel1 is an instance method, and you are sending it to a class (the +updateLabel1 instead of -updateLabel1 in the error message tells you this).

Since you've named your instance variables the same as the classes, you should be able to solve this by writing

[self.MetricPickerController updateLabel1];

instead - this makes it clear to the compiler you are referring to the instance variable and not the actual class.

Adrian B
  • 418
  • 3
  • 7
  • 2
    +1 Adopting the [`coding conventions`](http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html) of the platform would be a good way to go. – Deepak Danduprolu Jun 28 '11 at 08:42
  • Agreed, should have added a bit about that, ta. – Adrian B Jun 28 '11 at 09:03
  • Possibly a linked(not duplicate) question can be http://stackoverflow.com/questions/1053592/objective-c-class-vs-instance-methods – Praveen S Jun 28 '11 at 09:05
  • Hi Adrian thanks for your support and prompt answer i just plugged in the suggested fix and it worked - what a relief i have been scratching my head on this for ages. – superllanboy Jun 28 '11 at 11:02
  • Hi deepak thanks for your comment on the coding conventions, guess i need to think more carefully about these things rather than just forge ahead making basic mistakes. Thats the problem when you learn by doing i suppose with no one around to guide you. i am sure i will get more profficient as time goes by - meanwhile i will backtrack and try and correct the naming convention mistakes i have made – superllanboy Jun 28 '11 at 11:07