2015-04-22 153 views
-4

我想學習使用iOS構建應用程序。我使用Xcode 6.4,並且the tutorial I was following似乎接受使用樂趣和重寫,但是當我嘗試它時,它會帶來錯誤。我將受保護的頁面連接到我的註冊頁面。製作第一個iOS應用程序

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 

    - (void)ViewDidAppear(animated: bool) { 
     [self.PerformSegueWithIdentifier("LoginView", sender: self)]; 
    } 

} 

@end 

有人能幫我指出我的錯誤和解決方案嗎?

+5

爲什麼'didReceiveMemoryWarning'方法中的'viewDidAppear:'方法?爲什麼'viewDidAppear:'方法使用與其餘代碼不同的語言編寫? – rmaddy

+6

您正在使用Swift進行教程,但已經開始了一個使用Objective-C作爲默認語言的項目。 – Groot

+0

謝謝rmaddy我已經將didDceiveMemoryWarning中的ViewDidAppear方法移出,但仍然出現錯誤和語言位,我認爲我沒有更改語言,任何幫助使用正確的代碼將不勝感激 –

回答

4

歡迎SO通常,這不是一般的調試服務,但你可能喜歡腳踩上去......

  1. 在Objective-C方法不能內的其他方法聲明。它們可以在斯威夫特
  2. 斯威夫特代碼不能smooshed在靠Objective-C代碼。
  3. 案例是在雨燕的OBJ-C重要的,所以PerformSegueWithIdentifier是不一樣的performSegueWithIdentifier

所以正確版本的你正在嘗試做的是...

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 

} 

- (void)viewDidAppear:(BOOL)animated { 
    [self performSegueWithIdentifier:@"LoginView" sender:self]; 
} 

@end 

玩得開心,享受iOS開發。

3

您不能插入在另一個

方法定義在我以某種方式認爲你搞砸了斯威夫特和Objective C代碼, 你的代碼應該是這樣的:

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 


} 

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 

    [self performSegueWithIdentifier:@"LoginView" sender:self]; 
} 

@end 
+1

謝謝你,這個已經工作 –

-3

看起來像你只是試圖重寫viewcontrollers viewDidAppear方法。如果是這樣的話,該方法是在錯誤的地方(在你的代碼,它的內部didReceiveMemoryWarning

試試這個:

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)viewDidAppear:(BOOL) animated { 
    [super viewDidAppear:animated]; 
    [self.performSegueWithIdentifier("nameOfSeque", sender: self)]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
+0

這個答案仍然是在objC''[self.performSegueWithIdentifier()]中嵌入Swift點語法' – Wez

相關問題