What addTarget actions can I take in a UITextView?

I want to use addTarget: action in a UITextView, e.g. on (UITextField or UIButton).

I want to call a method in a UITextView.

please give some possible solution ...

Thanks...

UITextView *TXT_First_Tag = [[UITextView alloc] initWithFrame:CGRectMake(5, textPosY, 350, 65)]; TXT_First_Tag.backgroundColor = [UIColor whiteColor]; TXT_First_Tag.font = [UIFont fontWithName:@"Arial-BoldMT" size:30.0]; TXT_First_Tag.editable =YES; TXT_First_Tag.tag = i; TXT_First_Tag.textColor = [UIColor blackColor]; [TXT_First_Tag addTarget:self action:@selector(C6Loop) forControlEvents:UIControlEventEditingDidEnd]; // This Line I want to use, it working fine on textfield... [scrollview addSubview:TXT_First_Tag]; 
+6
source share
4 answers

UITextView delegate methods are used for this purpose.

Put this in your code.

 UITextView *TXT_First_Tag = [[UITextView alloc] initWithFrame:CGRectMake(5, textPosY, 350, 65)]; TXT_First_Tag.backgroundColor = [UIColor whiteColor]; TXT_First_Tag.font = [UIFont fontWithName:@"Arial-BoldMT" size:30.0]; TXT_First_Tag.editable =YES; TXT_First_Tag.delegate = self; TXT_First_Tag.tag = i; TXT_First_Tag.textColor = [UIColor blackColor]; [scrollview addSubview:TXT_First_Tag]; - (void)textViewDidBeginEditing:(UITextView *)textView{ NSLog(@"Begin editing"); } - (void)textViewDidEndEditing:(UITextView *)textView{ NSLog(@"DidEndEditing"); } - (BOOL)textViewShouldBeginEditing:(UITextView *)textView{ NSLog(@"ShouldBeginEditing"); return TRUE; } - (BOOL)textViewShouldEndEditing:(UITextView *)textView{ NSLog(@"ShouldEndEditing"); return TRUE; } 
+10
source

if u wants to perform some task before editing a text view than use

 -(void)textViewDidBeginEditing:(UITextView *)textView {} 

or if you want to do this after editing a text view, than use

 -(void)textViewDidEndEditing:(UITextView *)textView {} 

for this you need to add a protocol called UITextViewDelegate and write in viewdidload

 yourtextview.delegate = self; 
+2
source

Of course, the best way to get the "edit done end" message is to implement a UITextViewDelegate ?

 TXT_First_Tag.delegate = self; ... - (void)textViewDidEndEditing:(UITextView *)textView { // stuff you'd put in C6Loop 
0
source

Gaiters, Despite the fact that your answers did not solve my problem directly, it helped me narrow it down.

I have a text view in each cell and need to pass which text view was edited so that I can update the database.

In a nutshell, I set each textview tag in each cell in indexpath.row. Then I refer to this cell in the texthow.tag delegate

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyIdentifier = @"MyIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"frontCell" owner:self options:nil]; cell = mainPageCell; self.mainPageCell = nil; cell.selectionStyle = UITableViewCellSelectionStyleNone; } UITextView *trackDetails; trackDetails = (UITextView *)[cell viewWithTag:22]; trackDetails.text = [[myArray objectAtIndex:indexPath.row] objectAtIndex:0]; trackDetails.delegate = self; trackDetails.tag = indexPath.row; } - (void)textViewDidEndEditing:(UITextView *)textView { NSLog(@"%d",textView.tag); UPDATE DATABASE WITH CHANGED TEXT [textView resignFirstResponder]; [self.tableView reloadData]; } 
0
source

Source: https://habr.com/ru/post/912918/


All Articles