Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "cannot use an object as a parameter to a method"?

Tags:

objective-c

I have the following ViewController class

#import <UIKit/UIKit.h>

@interface SampleViewController : UIViewController {
    IBOutlet UITextField *field1;
}

@property (nonatomic, retain) UITextField *field1;

- (IBAction) method1:(id)sender; 
@end

When I change the method1:(id)sender to method1:(UITextField)sender, I get the error "Cannot use an object as a parameter to a method".

I searched and found this post which says "it [using an object as a method parameter] is not a good idea in Objective-C because Objective-C does not allow statically allocated object".

Can anyone point out where I can find a more detailed explanation for this?

Thank you.

like image 989
Martin08 Avatar asked May 10 '09 20:05

Martin08


1 Answers

You're not passing a pointer of UITextField.

method1:(UITextField)sender

should be

method1:(UITextField *)sender

Objective-C doesn't like it when you pass non-pointers for object types.

like image 146
Marc W Avatar answered Oct 16 '22 18:10

Marc W