在此视图中,除“说明”字段外,所有内容均为UITextfield
,“说明”字段为UITextView
。
所以我想要的是当我导航到这个视图时,
答案 0 :(得分:0)
使用验证器函数通过检查文本计数的任何字段是否为>来验证整个表单。 0.为了让您的生活更轻松,有一些验证器可供您使用,例如RAFieldValidator。在github上寻找更多信息。检查这些https://github.com/search?utf8=%E2%9C%93&q=form+validator+ios&type=
开始触发此功能,
对于文字字段:请查看UITextField text change event
对于TextView:您需要设置UITextView委托并在其中实现textViewDidChange:Method。
答案 1 :(得分:0)
查看以下示例,我希望它能为您提供帮助。
#import "SampleViewController.h"
@interface SampleViewController ()
@end
@implementation SampleViewController
- (void)viewDidLoad {
[super viewDidLoad];
_textview.delegate = self;
_secondButton.hidden = YES;
self.textview.layer.borderWidth = 2.0f;
self.textview.layer.borderColor = [[UIColor grayColor] CGColor];
self.navigationItem.hidesBackButton = YES;
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:@"< back" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
self.navigationItem.leftBarButtonItem = newBackButton;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)textViewDidBeginEditing:(UITextView *)textView{
_secondButton.hidden = NO;
}
- (void) back:(UIBarButtonItem *)sender {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Attention"
message:@"Are you sure want to discard this message."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
self.textview.text = nil;
[self.navigationController popViewControllerAnimated:YES];
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
NSLog(@"sandip");
[self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)secondButton:(id)sender {
}
@end