• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Die Bildungsoffensive hier im Forum geht weiter! Jetzt sollen Kreativität und technische Möglichkeiten einen neue Dimension erreichen. Das Thema in diesem Monat lautet - Verkehrte Welt - Hier geht es lang --> Klick

Use of undeclared identifier

christian.klugo

Erdapfel
Registriert
18.09.13
Beiträge
1
Hallo,

ich bin gerade dabei mit einem Buch mir selbst beizubringen, wie man Apps entwickelt. Bei dem Abschnitt, bei dem es darum geht sich für Notifications zu registrieren, komme ich ins Stocken und hoffe, dass Ihr mir weiterhelfen könnt.

Der Code sieht wie folgt aus:


- [(void)viewWillAppear:(BOOL)animated{

[[NSNotificationCenter defaultCenter]
addObserverForName: UIKeyboardWillShowNotification
object:self.view.window queue:nil
usingBlock:keyBoardWillShow];

[super viewWillAppear:animated];

Für die erste Zeile bekomme ich die Fehlerwarnung (Semantic issue): Use of undeclared identifizier "viewWillAppear".

Das Buch beschreibt den Umgang mit XCode 3, wobei ich mit XCode 4 programmiere. Meine Frage daher: Warum erscheint diese Fehlermeldung und was muss man in XCode 4 anders machen um sich für die Notifications zu registrieren?

Kennt außerdem möglicherweise jemand eine gute Übersicht der Dinge, die sich von XCode 3 zu XCode 4 geändert haben?

VG,
Christian
 
hast du den Code 1:1 rauskopiert?Falls ja: die "[" vor (void) ist dort fehl am Platz! ;)
 
Da ich nicht weiß aus welchem Buch du dir das Arbeiten mit "Notifications" angeschaut hast,
hier noch ein kleiner Beispielcode der die Verwendung vll. etwas klarer macht:

Code:
[COLOR=#0433FF]#import [/COLOR][COLOR=#B4261A]"ViewController.h"[/COLOR]

[COLOR=#0433ff]@implementation[/COLOR] ViewController


- ([COLOR=#0433ff]void[/COLOR]) viewWillAppear:([COLOR=#0433ff]BOOL[/COLOR])animated
{
[COLOR=#008F00]// Erzeugt ein UITextField um die Tastatur anzuzeigen.[/COLOR]
[COLOR=#3495AF][COLOR=#0433ff]self[/COLOR][COLOR=#000000].[/COLOR]view[COLOR=#000000].[/COLOR]backgroundColor[COLOR=#000000] = [[/COLOR]UIColordarkGrayColor[COLOR=#000000]];[/COLOR][/COLOR]
[COLOR=#3495AF]UITextField[COLOR=#000000] * textField = [[[/COLOR]UITextFieldalloc[COLOR=#000000]][/COLOR]init[COLOR=#000000]];[/COLOR][/COLOR]
    textField.[COLOR=#3495af]frame[/COLOR] = [COLOR=#3495af]CGRectMake[/COLOR](20, 20, 300, 40);
[COLOR=#3495AF][COLOR=#000000]    textField.[/COLOR]backgroundColor[COLOR=#000000] = [[/COLOR]UIColorlightGrayColor[COLOR=#000000]];[/COLOR][/COLOR]
    [[COLOR=#0433ff]self[/COLOR].[COLOR=#3495af]view[/COLOR] [COLOR=#3495af]addSubview[/COLOR]:textField];
    
[COLOR=#008F00]// Fügt einen Observer für die UIKeyboardWillShowNotification hinzu.[/COLOR]
[COLOR=#008F00]// Falls diese Notifcation "geworfen" wird, wird der Code in keyboardWillShowNotificationReceived ausgeführt.[/COLOR]
[COLOR=#3495AF][COLOR=#000000]    [[[/COLOR]NSNotificationCenterdefaultCenter[COLOR=#000000]] [/COLOR]addObserver[COLOR=#000000]:[/COLOR][COLOR=#0433ff]self[/COLOR][/COLOR]
                                             [COLOR=#3495af]selector[/COLOR]:[COLOR=#0433ff]@selector[/COLOR](keyboardWillShowNotificationReceived:)
                                                 [COLOR=#3495af]name[/COLOR]:[COLOR=#3495af]UIKeyboardWillShowNotification[/COLOR] [COLOR=#3495af]object[/COLOR]:[COLOR=#0433ff]nil[/COLOR]];
    [[COLOR=#0433ff]super[/COLOR] [COLOR=#3495af]viewWillAppear[/COLOR]:animated];
}


- ([COLOR=#0433ff]void[/COLOR])keyboardWillShowNotificationReceived:([COLOR=#0433ff]id[/COLOR])sender
{
[COLOR=#B4261A][COLOR=#3495af]NSLog[/COLOR][COLOR=#000000]([/COLOR]@"Notification Received"[COLOR=#000000]);[/COLOR][/COLOR]
}


[COLOR=#0433FF]@end[/COLOR]

PS: Benutze doch - falls du noch einmal Code kopierst - die entsprechende Formatierung von apfeltalk. Hilfe!
 
Zuletzt bearbeitet: