Why doesn't the keyboard appear in my UITextView?

I have a container class that is a view controller.
It contains a UITextView for notes and has another view controller as a subquery called PDFViewController. This has an array of view controllers, which they call in the PageViewController file, and UIScrollView so that I can scroll through the various view controllers from the array.

Each of PageViewController also has a UIScrollView, so I can scale different pages.

But when I show my UITextView, I cannot edit or write anything.
It shows a blinking cursor, but without a keyboard, and cannot write text.
When I select a word from the default text, it shows me some dictionary options, but the words will not be replaced.

I just don't know where the problem might be.

container.m (View Controller)

- (void) initNotes {

notesVisible = FALSE;
notes = [[UITextView alloc]initWithFrame:CGRectMake(10, 10, note_width, note_height)];
notes.backgroundColor = [UIColor yellowColor];
notes.font = [UIFont fontWithName:@"Arial" size:24];  
notes.text = @"Hier ist Platz für Ihre Notizen";

container = [[UIView alloc] initWithFrame:CGRectMake(start_x, start_y, container_width, container_height)];
container.backgroundColor = [UIColor yellowColor];
[container.layer setShadowColor:[[UIColor blackColor] CGColor]];
[container.layer setShadowOffset:CGSizeMake(2.0, 3.0)];
[container.layer setShadowOpacity:0.6];
[container.layer setShadowRadius:5];
container.layer.shouldRasterize = YES;
[container addSubview:notes];
[self.view addSubview:container];
}

- (void) showTextView {
[UIView beginAnimations:@"MoveAndStrech" context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

container.frame = CGRectMake(start_x, self.view.center.y-container_height, container_width, container_height); 

[UIView commitAnimations];

notesVisible = !notesVisible;
}

- (void) hideTextView {

[UIView beginAnimations:@"MoveAndStrech" context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

container.frame = CGRectMake(start_x, start_y, container_width, container_height); 

// [notes resignFirstResponder];
[UIView commitAnimations];

notesVisible = !notesVisible;
}

@implementation PDFViewController

- (void)awakeFromNib
{
painting = false;
dataInstance = [PDFDataInstance sharedInstance];
chapter = [dataInstance chapter];
[self getNumberOfPages];
kNumberOfPages = dataInstance.pages;

// Register observer to be called when a cell from BookmarkPDFController is pressed
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(didSelectBookmark:) 
                                             name:@"bookmarkPressedinPDFView" object:nil];
// Register observer to be called when a cell from BookmarkPDFController is pressed
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(togglePainting:) 
                                             name:@"togglePainting" object:nil];

    // view controllers are created lazily
// in the meantime, load the array with placeholders which will be replaced on demand
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++)
{
    [controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];

// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.delegate = self;
scrollView.directionalLockEnabled = YES;

currentPage = [[chapter currentPage] integerValue];


// pages are created on demand
// load the visible page
// load the page on either side to avoid flashes when the user starts scrolling
// 
// Load pages based on currentPage cause of when coming from bookmarks
[self loadScrollViewWithPage:currentPage];
[self loadScrollViewWithPage:currentPage+1];

// update the scroll view to the appropriate page
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * currentPage;
frame.origin.y = 0;
[scrollView scrollRectToVisible:frame animated:YES];


}

- (void)loadScrollViewWithPage:(int)page
{
if (page < 0)
    return;
if (page >= kNumberOfPages)
    return;

// replace the placeholder if necessary
PageViewController *controller = [viewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null])
{
    //page+1 cause CGPDF indexing starts with 1
    controller = [[PageViewController alloc] initWithPageNumberAndUrl:page+1: [chapter urlOnFilesystem]];
    [viewControllers replaceObjectAtIndex:page withObject:controller];
    [controller release];
}

// add the controller view to the scroll view
if (controller.view.superview == nil)
{
    CGRect frame = scrollView.frame;
    frame.origin.x = frame.size.width * page;
    frame.origin.y = 0;
    controller.view.frame = frame;

    [scrollView addSubview:controller.view];

}
}

TextView delegates

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

NSLog(@"begin editing");
}

- (BOOL)textView:(UITextView *)aTextView shouldChangeTextInRange:(NSRange)aRange replacementText:(NSString*)aText
{
NSLog(@"something changed"); 
return YES; 
}
+3
source share
10 answers

UITextView ? UITextViewDelegate , (esp textViewDidBeginEditing: textView: shouldChangeTextInRange: replacementText:). , , .

, ( , , )

+4

. iOS , "Hardware/Keyboard/Connect Hardware Keyboard" . , . , , . : (

Menu

, Connect Hardware Keyboard UN.

+50

, :

notes.editable = YES ; 

?

+2

, . YES.


- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
  return YES;
}
+2

UITextViewDelegate notes.delegate = self; notes initNotes.

+1

2 :

  • notes.editable = YES; , , .

2. , UITextView. , , notes.delegate = self.

+1

container, UITextView (notes) . , , .

:

[container addSubview:notes];
[self.view addSubview:container];

:

[self.view addSubview:notes];

, .

+1

, , .

- (void)textViewDidBeginEditing:(UITextView *)textView {
    if ([textView isEqual:notes]) {
        NSLog(@"notes begin editing");
    }
}

- (BOOL)textView:(UITextView *)aTextView shouldChangeTextInRange:(NSRange)aRange replacementText:(NSString*)aText {
    if ([aTextView isEqual:notes]) {
        NSLog(@"something changed in notes");
    }

    return YES; 
}

, .

+1

, UITextView .

My UITextView UICollectionView, , UITextView .

, UICollectionView , UITextView . .

, .

0

. . ContantView / , _bubbletable - .

- (void)keyboardWasShown:(NSNotification*)aNotification
 {
 NSDictionary* info = [aNotification userInfo];
 CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

  [UIView animateWithDuration:0.2f animations:^{

    CGRect frame = _ContantView.frame;
    frame.origin.y -= kbSize.height;
    _ContantView.frame = frame;

    frame = _bubbleTable.frame;
    frame.size.height -= kbSize.height;
    _bubbleTable.frame = frame;

}];

}

0

All Articles