UA-17470720-3

Jump to content


Photo
- - - - -

SCTextViewCell Jumping


  • Please log in to reply
6 replies to this topic

#1 Andrew_P

Andrew_P

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 22 posts
Reputation: 5
Good

Posted 25 September 2015 - 08:44 AM

Hey Everyone, 

 

      I've created a video of an issue i've been having with the SCTextViewCell (It was easier than describing it!) https://youtu.be/qTmloAI7cM4. It seems to be related to the cell being near the end of the section when it scrolls to keep the textview in focus. 

 

To recreate it the issue, you can use the Tasksapp Sample code. In interface builder move the "Details" property to the bottom in the group. Or alternatively, delete all the properties underneath "Details". Then keep typing in the TextView.

 

Kind Regards

 

Andrew

 


  • designwerks likes this

#2 designwerks

designwerks

    Advanced Member

  • STV 5.0 Std
  • PipPipPipPipPip
  • 141 posts
  • LocationKingsville, Ontario, Canada
Reputation: 23
Excellent

Posted 25 September 2015 - 06:29 PM

My app does the same.  Haven't had time to look at it, but for the record, you are not alone...

 

John



#3 Andrew_P

Andrew_P

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 22 posts
Reputation: 5
Good

Posted 07 October 2015 - 01:43 PM

John, it's always good to know i'm not alone! I might have a bit of a hacky solution, do you know if this problem existed pre iOS 9?

 

Andrew



#4 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 07 October 2015 - 02:51 PM

Greetings Programs!

 

I was discussing it in this thread (http://sensiblecocoa...and-scdatecell/) too :) .

 

So the textviews are in cells at the end of the tableview and the cell is being re-positioned/scrolled to a certain distance above the keyboard so you can type freely but because it's at end of the tableview, the tableview bounces back down.

 

My app doesn't have a footer so what I did was add a footer with enough height that when the textviews in the last couple of cells are typed in and scrolled up, there is enough of the tableview to move up and not bounce the textview.

 

tableViewModel.tableView!.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: tableViewModel.tableView!.frame.size.width, height: 300))

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#5 Andrew_P

Andrew_P

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 22 posts
Reputation: 5
Good

Posted 09 October 2015 - 03:42 AM

Hey Wizgod,

 

That's a good solution! It seems as though the height of the footer is related to the amount of text and you can scroll the tableview down over that footer. I've been messing around with the idea of disabling the animations of the tableview so the textview doesn't scroll the tableview.

 

I'm not sure the rules of posting source code but i'll do my best to explain..

 

When the text changes, calculate the height.

If the new height is not equal to the old height we will change the cell height, by allowing the tableview to begin updates.

 

Disable the animations before beginning updates like this..

 

        [UIView setAnimationsEnabled:NO];
        [self.ownerTableViewModel.tableView beginUpdates];
        [self.ownerTableViewModel.tableView endUpdates];
        [UIView setAnimationsEnabled:YES]; 

Then scroll to the text position, with the animate parameter set to NO.

 

I'll keep playing around with it until i find a better solution, i'll also try and come up with a way you don't need to change the source incase you don't have access to it.



#6 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 09 October 2015 - 07:26 AM

In the past, I would use the UIKeyboardWillShowNotification and UIKeyboardWillHideNotification to offset the tableview and then restore the position. Just offsetting it won't work anymore because of the resizing feature of the textview and cell but looking back at that code gave me an idea and I merged my current solution with it.

 

I only add/increase the footerview height when the keyboard is going to appear and remove it when it's dismissing. This way the user never sees/has to deal with an excessively tall footer and the textview/cell resizing works as normal.

 

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
}

override func viewWillDisappear(animated: Bool) {
    
    NSNotificationCenter.defaultCenter().removeObserver(self, name: "keyboardWillShow", object: nil)
    NSNotificationCenter.defaultCenter().removeObserver(self, name: "keyboardWillHide", object: nil)

    super.viewWillDisappear(animated)
}

func keyboardWillShow(notification: NSNotification)  {
    tableViewModel.tableView!.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: tableViewModel.tableView!.frame.size.width, height: 300))
}

func keyboardWillHide(notification: NSNotification) {
    tableViewModel.tableView!.tableFooterView = nil
}

 

Just to note, there are internal methods in SCTableViewModel for keyboardWillHide: and keyboardWillShow:.

 

@Tarek, I wonder if maybe there could be an action created for these two methods to do things like above?

 

Wg


Edited by wizgod, 09 October 2015 - 07:33 AM.

  • Tarek likes this

P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#7 Andrew_P

Andrew_P

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 22 posts
Reputation: 5
Good

Posted 15 October 2015 - 04:40 AM

Hey Wizgod, just wanted to say that fix works perfectly!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users