2011-06-30 51 views
0

我正在通過創建應用程序的教程。我一直跟着,並且一切都寫得像教程一樣。但是,當我點擊構建時,我收到了一些錯誤。 下面是我在實現文件中的一個方法的代碼片段。我得到一個錯誤....(scrollTheView'未聲明)...我還有另一個錯誤堆積它是(預期';'之前':'代幣).....錯誤「scrollTheView」未聲明的問題

在此之下方法我將包括我的整個頭文件,我已經聲明瞭方法「scrollTheView」,所以我不明白我出錯的地方。本教程使用SDK iPhone OS 2.2.1,但是我使用的是SDK 4.3,這可能是導致此問題的真正原因嗎?我已經編輯過這個帖子來包含整個實現文件。在代碼的最後,我還得到了一個錯誤,「在輸入結束時出現預期的聲明或聲明」,另一個錯誤是在實現上下文中缺少'@end'謝謝所有那些查看並試圖幫助我的人。
謝謝斯科特幫我用那個缺少的支架..現在我有一個通知,即使它編譯彈出。「UIKeyboardBoundsUserInfoKey已棄用通知」任何人都知道這意味着什麼?當它編譯時,我應該擔心嗎?它出現在的線「NSValue *安勤......」項下的方法行‘keyboardWillShow’

#import "ReturnToMeViewController.h" 
#import "ReturnToMeAppDelegate.h" 

@implementation ReturnToMeViewController 

@synthesize textField; 
@synthesize label; 
@synthesize callNumber; 

-(void)viewDidLoad { 
    textField.clearButtonMode = 
    UITextFieldViewModeWhileEditing; 
    [super viewDidLoad]; 
} 




-(void) viewWillAppear:(BOOL)animated { 
    [[NSNotificationCenter defaultCenter] addObserver:self 
        selector:@selector(keyboardWillShow:) 
         name:UIKeyboardWillShowNotification 
         object:self.view.window]; 
    [super viewWillAppear:animated]; 
} 

-(void) viewWillDisappear:(BOOL)animated { 

    [[NSNotificationCenter defaultCenter] removeObserver:self 
      name:UIKeyboardWillShowNotification object:nil]; 
    [super viewWillDisappear:animated]; 
} 

-(void)keyboardWillShow: (NSNotification *)notif { 

    NSDictionary* info = [notif userInfo]; 

    NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey]; 
    CGSize keyboardSize = [aValue CGRectValue] .size; 
    float bottomPoint = (textField.frame.origin.y+textField.frame.size.height+10); 
    scrollAmount = keyboardSize.height - (self.view.frame.size.height- bottomPoint); 

    if (scrollAmount >0) { 
     moveViewUp =YES; 
     [self scrollTheView:YES]; 
    } 
    else { 
     moveViewUp =NO; 

    } 



-**(void) scrollTheView:(BOOL) movedUp {** 

     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.3]; 
     CGRect rect = self.view.frame; 
     if (movedUp) { 
      rect.origin.y -= scrollAmount; 
     } 
     else { 
      rect.origin.y += scrollAmount; 
     } 
     self.view.frame = rect; 
     [UIView commitAnimations]; 
    } 

-(void)touchesBegan: (NSSet *) touches withEvent: (UIEvent *)event { 
     if (textField.editing) { 
      [textField resignFirstResponder]; 
      [self updateCallNumber]; 
      if (moveViewUp) [self scrollTheView:NO]; 
     } 
     [super touchesBegan:touches withEvent:event]; 
    } 



-(void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

-(void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


-(void)dealloc { 
    [textField release]; 
    [label release]; 
    [callNumber release]; 
    [super dealloc]; 
} 

    -(BOOL)textFieldShouldReturn: (UITextField *)theTextField { 

     [theTextField resignFirstResponder]; 
     if (moveViewUp) [self scrollTheView:NO]; 
     [self updateCallNumber]; 

     return YES; 
    } 

-(void)updateCallNumber {  
     self.callNumber = textField.text; 
     label.text = self.callNumber; 
    } 

@end 


###ReturnToMeViewController.m 

    #import <UIKit/UIKit.h> 

    @interface ReturnToMeViewController : UIViewController 
     <UITextFieldDelegate> { 
     IBOutlet UITextField *textField; 
     IBOutlet UILabel *label; 
     BOOL moveViewUp; 
     CGFloat scrollAmount; 
     NSString *callNumber; 

    } 

    @property (nonatomic, retain) UITextField *textField; 
    @property (nonatomic, retain) UILabel *label; 
    @property (nonatomic, retain) NSString *callNumber; 

    - (void)scrollTheView:(BOOL) movedUp; 
    - (void)updateCallNumber; 

    **@end** 
+1

你在哪裏得到構建錯誤?雙擊錯誤框中的錯誤通常會讓您感到困惑。 –

+0

從哪裏以及如何調用scrollTheView:方法? – EmptyStack

+0

請格式化所有的代碼 – vikingosegundo

回答

0

聽起來像是你缺少一個右括號‘}’或分號‘;’在scrollTheView函數之前的某處。

0

有可能是錯誤之前你聲明scrollTheView,這意味着它無法檢測到scrollTheView。在這裏看看或發佈更多的代碼。

0

您在keyboardWillShow:(NSNotification *)notif方法末尾丟失了右括號。

if (scrollAmount >0) { 
    moveViewUp =YES; 
    [self scrollTheView:YES]; 
} 
else { 
    moveViewUp =NO; 
} // This is where the missing bracket should be 
} 

有需要是兩個右括號 - 一個用於if聲明,一個用於方法 - 但只有一個。

+0

聖潔的廢話!謝謝Scott!最快的答覆我見過,不僅如此,但解決了它..它編譯..但是我也有一個「UIKeyboardBoundsUserInfoKey已棄用通知」任何人都知道這意味着什麼?當它編譯時,我應該擔心嗎? – shin