Iphone UIViewController无法识别方法

Iphone UIViewController无法识别方法,iphone,objective-c,cocoa-touch,uiviewcontroller,Iphone,Objective C,Cocoa Touch,Uiviewcontroller,请帮我解决这个问题 我在导航堆栈中有一个名为firstviewcontroller的视图控制器 -(IBAction)toggleUnit { selectedUnit = [segmentedControl selectedSegmentIndex]; if (selectedUnit == METRIC_INDEX) { [MetricPickerController updateLabel1]; <<<<< (Metr

请帮我解决这个问题

我在导航堆栈中有一个名为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 
    }
FirstViewController.h FirstViewController.m MetricPickerController.h 问题是我在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 
    }
-(iAction)切换单元
{
selectedUnit=[segmentedControl selectedSegmentIndex];
if(selectedUnit==度量索引)
{

[MetricPickerController updateLabel1];问题在于
updateLabel1
是一个实例方法,您正在将它发送到一个类(错误消息中的
+updateLabel1
而不是
-updateLabel1
告诉您这一点)

由于您已将实例变量命名为与类相同的名称,因此应该能够通过编写

[self.MetricPickerController updateLabel1];

相反-这向编译器表明您引用的是实例变量,而不是实际的类。

问题在于
updateLabel1
是一个实例方法,您将它发送到一个类(错误消息中的
+updateLabel1
而不是
-updateLabel1
告诉您这一点)

由于您已将实例变量命名为与类相同的名称,因此应该能够通过编写

[self.MetricPickerController updateLabel1];

相反-这让编译器清楚地知道,您指的是实例变量,而不是实际的类。

请参见下面Adrian的回答。我建议一个好的命名方案是,使用小写字母作为实例变量,大写字母作为类名,这将在将来有所帮助。@Nick Bull 100%支持您。命名是非常重要,而且确实有助于减少bug。请参见下面Adrian的答案。我建议一个好的命名方案是使用小写字母作为实例变量的首字母,大写字母作为类名,这将有助于将来实现这一点。@Nick Bull 100%同意您的意见。命名非常重要,而且确实有助于减少bug。+1采用platf的orm将是一个很好的方法。同意,应该增加一点,ta。可能是一个链接(不是重复)问题可以是Hi Adrian谢谢你的支持和及时的回答我刚刚插入了建议的修复程序,它起了作用-这是我多年来一直在挠头的一种解脱。Hi deepak谢谢你对编码约定的评论,我想我需要更仔细地考虑这些事情,而不是继续做基本的MISAkes。我想这是在没有人指导的情况下,当你通过实践学习时的问题。我相信随着时间的推移,我会变得更加丰富-同时,我会回溯并尝试纠正我犯下的命名约定错误+1采用平台的名称将是一个很好的方式。同意,应该增加一点,ta。可能链接的(非重复的)问题可以是Hi Adrian谢谢你的支持和及时的回答我刚刚插入了建议的修复程序,它起了作用-这是我多年来一直在挠头的一种解脱。Hi deepak谢谢你对编码约定的评论,我想我需要更仔细地考虑这些事情,而不是继续做基本的MISA凯斯。我想,在没有人指导的情况下,当你从实践中学习时,这就是问题所在。我相信随着时间的推移,我会变得更加丰富——与此同时,我会回溯并尝试纠正我犯下的命名惯例错误
-(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 
    }
[self.MetricPickerController updateLabel1];