0
我是新來使用塊語法並面臨以下問題。下面的代碼調用導致問題的類的另一個靜態方法。下面的代碼被點擊下一個按鈕在欄上調用。這段代碼的語法有沒有錯誤?使用塊時選擇器沒有已知的類方法
-(BOOL) shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
if (![sender isKindOfClass:[UIBarButtonItem class] ]) {
return true;
}
// Trim the spaces
self.stewardsNameTextField.text = [self.stewardsNameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ];
self.trackNameTextField.text = [self.trackNameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ];
self.curatorNameTextField.text = [self.curatorNameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ];
bool isValid =[JLTValidator validateFields: @[self.stewardsNameTextField, self.trackNameTextField, self.curatorNameTextField, self.weatherConditionSegment, self.trackConditionSegment] withScrollToCallback: ^(UIView * invalidField) // problem is here. Is this incorrect syntax?
{
if (invalidField == self.stewardsNameTextField || invalidField == self.trackNameTextField || invalidField == self.curatorNameTextField)
{
[invalidField becomeFirstResponder];
}
else
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
CGPoint top = CGPointMake(0, invalidField.frame.origin.y - 90);
[_scrollView setContentOffset:top animated:YES];
_scrollView.scrollIndicatorInsets=contentInsets;
}
if (!isValid) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:@"Please fill out the marked fields." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
return isValid;
}];
}
靜態方法的定義被稱爲對類:
+(BOOL)validateFields:(NSArray *)fields
{
return [JLTValidator validateFields:fields withScrollToCallback:nil];
}
+(BOOL)validateFields:(NSArray *)fields andShouldDisplayMessage : (bool) shouldDisplayMessage
{
return [JLTValidator validateFields:fields withScrollToCallback:nil andShouldDisplayMessage:shouldDisplayMessage];
}
+(BOOL)validateFields:(NSArray *)fields withScrollToCallback : (void (^) (UIView *))scrollToCallback
{
return [JLTValidator validateFields:fields withScrollToCallback:scrollToCallback andShouldDisplayMessage:true];
}
+(BOOL)validateFields:(NSArray *)fields withScrollToCallback : (void (^) (UIView *))scrollToCallback andShouldDisplayMessage : (bool) shouldDisplayMessage
{
}
請告訴我錯在這裏?請指導。
什麼是你想實現與回調?它應該返回一個BOOL嗎? – Wain
wain ..是的,你是對的。它返回一個布爾值。 – LUI