2011-07-01 5 views
1

"x"、 "y" "object"を渡して移動させる一般的なメソッドを記述しようとしています。私はそのようにようにそれを呼びたいButtonオブジェクトをメソッドに渡す

-(void) changeObjectLocations: (integer_t) xSpot: (integer_t) ySpot: (id) sender { 

    if (![sender isKindOfClass:[UIButton class]]) 
    { 
     UIButton *myObject = (UIButton *)sender; 
     [UIView animateWithDuration:1.5    
     animations:^{     
     CGRect newFrame = myObject.frame; 
     newFrame.origin.x = xSpot; 
     newFrame.origin.y = ySpot; 
     myObject.frame = newFrame; 
    }];    
} 
    else if (![sender isKindOfClass:[UILabel class]]) 
    { 
    UILabel *myObject = (UILabel *)sender; 
    [UIView animateWithDuration:1.5 animations:^{     
     CGRect newFrame = myObject.frame; 
     newFrame.origin.x = xSpot; 
     newFrame.origin.y = ySpot; 
     myObject.frame = newFrame; 
    }]; 
    } 
} 

-(void) orientationBlockLandscape { 

    [self changeObjectLocations: 456 :282 : btn1] ; 
    [self changeObjectLocations: 391 :227 : lblTitle] ; 

} 

それはコンパイルに、取り組んでいるが、私は次の警告を得る:

SecondViewController.m:33現在、私はこれを持っています:警告: 'SecondViewController'が '-changeObjectLocations :::'に応答しない可能性があります

オブジェクトを渡すことができますか?すべてのヘルプに事前に感謝します。あなたはSecondViewControllerのヘッダーにchangeObjectLocationsを定義していないよう

ジオ...

出力する警告に基づいて

答えて

1

、それが聞こえる - またはそれはあなたが実装されたものと同じシグネチャではありません。

+0

それでした。私はいつも何かを忘れるので、Objective-Cの初心者です!ありがとう – George

+0

@問題ありません。途中で素晴らしい名前! ;) –

0

コンパイラは、変数を持つメソッド定義であるセレクタを検索し、戻り値を削除します。

だから、のような方法:

-(void) setObject:(id) anObject forKey:(NSString *) keyname; 

は...のセレクタなければなりません。そのため

setObject:forKey: 

を、あなたの方法:

-(void) changeObjectLocations: (integer_t) xSpot: (integer_t) ySpot: (id) sender 

は...持っていますセレクタ:

changeObjectLocations:xSpot:ySpot: 

パラメータ名はそうセレクタの一部であることに注意してください。

changeObjectLocations:xSpot:ySpot: 

changeObjectLocations::: 

.. 2つの全く別の方法を表す2つの完全に別個のセレクタです。

名前のないパラメータを使用することは言語上合法ですが、 ":::"というのは、ネーミングの衝突を起こしやすいため、非常に貧弱な方法です。明示的であれば、コードを読みやすく保守しやすくするだけでなく、コンパイラとランタイムが機能しやすくなります。

関連する問題