如何覆盖Swift委托方法以获取更多参数?

时间:2019-03-07 21:20:06

标签: ios swift cocoa-touch uikit

我有一个带有3个UITextField的表单。当用户在该特定字段中输入完文本后,我想验证每个字段的用户输入。现在,我有一种方法

validateAllFields()
我打来的

func textFieldDidEndEditing(_ textField: UITextField) {
    self.validateAllFields()
}

我宁愿在修改文本后验证单个字段,而不是在修改每个字段后验证所有字段。

是否可以重写委托方法或扩展UITextField以采用更多参数?像这样:

override func textFieldDidEndEditing(_ textField: UITextField,
                       textFieldIdentifier: TextFieldIdentifierEnum) {
    self.validate(textField: textField, basedOn: textFieldIdentifier)
}

我怀疑可以通过扩展来完成,但是我不清楚如何进行。

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

您不必这么做,因为DELETE CASCADE参数会为您提供用户更改的当前文本字段

假设你有

plt.rcParams['figure.figsize'] = [14.0, 7.0]

e1 = cv2.getTickCount()
#read image and convert to RGB
image_normal = cv2.imread(image)
image_query = cv2.cvtColor(image_normal, cv2.COLOR_BGR2RGB)
image_gray  = cv2.cvtColor(image_query, cv2.COLOR_RGB2GRAY)

#ORB function
orb = cv2.ORB_create()
keypoints, descriptor = orb.detectAndCompute(image_gray, None)

# Draw the keypoints 
image = cv2.drawKeypoints(image_query, keypoints,0,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
mean, eigenvectors = cv2.PCACompute(image, np.mean(image, axis=0).reshape(1,-1))          

e2 = cv2.getTickCount()
t = (e2 - e1) / cv2.getTickFrequency() 

#Show Image
plt.imshow(image)
plt.title('ORB Keypoints')
plt.show()

# Print the number of keypoints detected and time
print("\nNumber of keypoints Detected: ", len(keypoints))
print('Time Cost for ORB: ', (t))

(_ textField: UITextField)