Reputation: 313
i am new to Obejctive C, so please forgive me if this is a simple question. i am trying to get the below code to work (from the Facebook IOS integration tutorial),but i get an error at the line
- (void) logoutButtonClicked:(id)sender {
[facebook logout];
I get the error
"use of undeclared identifier" logoutButtonClicked. I know that this is saying i am implementing a method that is not defined. So my question is, where is the method being defined in the code below?
i have seen a solution here posted but it does not work for me, this error persists. I have tried alternatives to try and fix, but could some one please confirm what this block of code is doing.
My understanding is that, we start of creating a pointer (logoutButton) to UIButton, and we then set the parameters of it. We then use a selector to define an action message (LogoutButtonClicked), for the method UIControlEventTouchInside.
I don't fully understand how the method is being declared, because I thought that the line here is defining the instance method:
-(void) logoutButtonClicked:(id)sender {
[facebook logout];
Or is the method being declared in
[logoutButton addTarget:self action:@selector(logoutButtonClicked)
forControlEvents:UIControlEventTouchUpInside];
// Add the logout button
UIButton *logoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
logoutButton.frame = CGRectMake(40, 40, 200, 40);
[logoutButton setTitle:@"Log Out" forState:UIControlStateNormal];
[logoutButton addTarget:self action:@selector(logoutButtonClicked)
forControlEvents:UIControlEventTouchUpInside];
[self.viewController.view addSubview:logoutButton];
// Method that gets called when the logout button is pressed
- (void) logoutButtonClicked:(id)sender {
[facebook logout];
}
i would really appreciate someones help on this , have been struggling with trying to understand this to no avail.
Melvin
Upvotes: 1
Views: 341
Reputation: 90551
You appear to be defining a method right smack in the middle of another method. You can't do that. The lines:
- (void) logoutButtonClicked:(id)sender {
[facebook logout];
}
have to appear outside of any other method, not within the curly braces ({
... }
) of another method.
Upvotes: 2
Reputation: 104698
The colon is part of the selector's name:
@selector(logoutButtonClicked:)
^
NOT
@selector(logoutButtonClicked)
Upvotes: 3