私は iOS が初めてで、適切な方法を学んでいます。頭をもたげたもう 1 つの質問は、条件に基づいてメソッドの実行を停止し、コードの呼び出しに戻るにはどうすればよいかということです。通常、PHP では、ネストされた条件文内に巨大なコード ブロックを押し込むのではなく、単純にtrue
/false
を返すか、例外をスローしますが、iOS では、IBAction のリターン シグネチャを使用してメソッドから戻ることは許可されていません。
このシッチを処理する好ましい方法は何ですか?
- (IBAction)submitCode:(id)sender
{
if ([codeEntry.text length] == 0) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Form Validation" message:@"No code entered, please try again."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
// IOS not allowing this
return NO;
}
// Prefer not to wrap the rest of the logic in an else, rather just cease
// execution and return back to calling code
NSLog(@"I would have submitted!");
}