我正在使用带有 UITextView 子视图的 AlertView 来让用户回复我的应用程序中的帖子,但是我希望当用户键入的字符数超过字符限制时禁用警报的回复按钮。像这样禁用警报视图按钮会让我的应用程序被拒绝,有没有更好的方法来做到这一点?
-(void)textViewDidChange:(UITextView *)textView {
if (!replyAlert) {
return;
}
//character count
replyAlert.title = [NSString stringWithFormat:@"Reply to Post (%i/250)", [textView.text length]];
if ([textView.text length]>=250) {
//disable alert view button
for (UIView* view in [replyAlert subviews])
{
if ([[[view class] description] isEqualToString:@"UIAlertButton"])
{
UIButton *button = (UIButton*)view;
if ([button.titleLabel.text isEqualToString:@"Reply"]) {
//disable
button.enabled = NO;
}
}
}
} else if ([textView.text length]==249) {
//re-enable button if user deleted a character
for (UIView* view in [replyAlert subviews])
{
if ([[[view class] description] isEqualToString:@"UIAlertButton"])
{
UIButton *button = (UIButton*)view;
if ([button.titleLabel.text isEqualToString:@"Reply"]) {
//enable
button.enabled = YES;
}
}
}
}
}