Textview caret/cursor is cut off at the bottom ios8 - xcode

I have been struggling with what may be a bug in Xcode 6.0.1. I am building an app which has a similar scene as the apple compose section in the mail app. I am using
func textViewDidChange(textView: UITextView) {
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
which calls tableView.estimatedRowHeight and tableView.rowHeight = UITableViewAutomaticDimension in order to resize the cell accordingly using auto layout and simple constraints. I have cell.mytextview.delagete = self. This works flawlessly in my other scene where the text is is not entered by the user.
The problem is it appears that the cell caret/cursor is getting cut off when text reaches the keyboard or bottom of the screen. Also, if I press return repeatedly without entering text the caret/cursor disappears altogether for about 6 times until it scrolls me down to the bottom with the cursor still cut off. What I have realized is if I put 5 rows of text and then start back from rows enter text normally it works fine. Visually it looks similar to this. It just seems there is some gap where it is not auto scrolling to the correct place. I should also mention that the cell and textview are expanding because I can scroll down and see the text. I have already tried removing the other cells to see if they may have been causing the issue, but it had no effect. I have searched very hard on this and came up empty handed. Here is some relevant code.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cellidentifier : String?
if indexPath.row == 0 {
cellidentifier = "tocell"
}
if indexPath.row == 1 {
cellidentifier = "subjectcell"
}
if indexPath.row == 2 {
cellidentifier = "bodycell"
}
let cell = tableView.dequeueReusableCellWithIdentifier(cellidentifier!) as composeTableViewCell
if indexPath.row == 0 {
cell.tofield!.text = toString
cell.tofield?.delegate = self
}
if indexPath.row == 1 {
cell.subjectfield?.delegate = self
}
if indexPath.row == 2 {
cell.bodyfield?.delegate = self
}
return cell
}

i hope this will use full until the Xcode fix the bug
use
enter code hereview.content = CGSizeMake(0,800) //like this and implement as per orientation

Related

Why the table cell default selection style is not returned? Swift 5.2

Why the default style for the selectionStyle property in the tableview cell is not returned? I wrote a condition to check and the print command works, i.e. it shows that default style is returning. But the table cell is not grayed out, as it should be with the default style.
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
if cell?.selectionStyle == .default {
cell?.selectionStyle = .none
print("none")
} else {
cell?.selectionStyle = .default
print("default")
}
}
I found a solution to the problem. The fact is that the return of the style works, it just is not visible, because the change is very fast.
To see how the cell selection style changes (white color changes to gray and vice versa) you just need to click on the cell and hold it pressed for a while. And then you can see how the cell is grayed out.

How to create table with highlighted-on-mouseover cells on macOS cocoa?

I'm trying to create a tray popover app with table very similar to the one Dropbox has in it's popover view.
There is a table of files and when you hover mouse over a table cell, cell will highlight and show additional controls.
I'm not sure if NSTableView is suitable for this at all?
Does anyone have any advice?
This would be an ideal use of NSTableView. Using a view-based NSTableView, you'll be easily able to create the look of those cells (views). The highlight on mouse-over should be accomplishable if you add an NSTrackingArea to the table view (scroll view might be better) with -[NSView addTrackingArea:], which gives you callbacks for -mouseMoved: events. From that method you can use the locationInWindow property on the NSEvent, and then use NSTableView's -rowAtPoint: call to query which row you should change to display the hover event.
As a possible amendment here, I had to do the following to make this work:
highlightedRow: MyCustomRow?
func viewWillAppear(){
configureTableHighlight()
}
func configureTableHighlight() {
let trackingArea = NSTrackingArea(rect: scrollView.frame, options: [.mouseMoved, .activeInKeyWindow, .inVisibleRect], owner: self, userInfo: nil)
scrollView.addTrackingArea(trackingArea)
}
override func mouseMoved(with event: NSEvent) {
let pointInTableView = tableView.convert(event.locationInWindow, to: nil)
let row = tableView.row(at: pointInTableView)
if row == -1 {
highlightedRow?.highlight = false
highlightedRow = nil
return
}
guard let view = tableView.view(atColumn: 0, row: row, makeIfNecessary: false) as? MyCustomRow else {
return
}
if(highlightedRow == view){
return
}
view.highlight = true;
highlightedRow?.highlight = false
highlightedRow = view;
}
This might depend on where you add the trackingView however.
Additional reference:
mouseover detection in NSTableView's NSCell?

tvOS collection view cell

I noticed you have to use .adjustsImageWhenAncestorFocused to 'pop' the collection view cell's image when focused. This has created a problem for me, without .adjustsImageWhenAncestorFocused the images are fine, but with that method, it crops my images on the top and bottom.
Did anyone run into this and solve it? I tried .clipsToBounds = true but that doesn't solve my problem.
You could make your UICollectionView bigger, or use this method to control the focus animation:
let originalImageSize = CGSizeMake(100, 100)
let focusedImageSize = CGSizeMake(120, 120)
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
coordinator.addCoordinatedAnimations({ [unowned self] in
if self.focused {
self.imageView.frame.size = focusedImageSize
}
else {
self.imageView.frame.size = originalImageSize
}
}, completion: nil)
}
You need to add this code to your custom UICollectionViewCell class. Hope it helps.

TableViewCell with UITextView not aligned and cutted until scolling

I've a TableViewCell with a UITextView, which content is not aligned and cutted at bottom at the first display:
When I scroll down and then up to the top, everything is fine:
My cellForRowAtIndexPath to get the content from a fetchedResultsController is simple:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("TextViewCell") as! TextViewCell
let data = self.fetchedResultsController.objectAtIndexPath(indexPath) as! NSManagedObject
let text = data.valueForKey("textDu")!.description
cell.textContentView.text = text
return cell
}
How can I get the result after scrolling after start???
Use sizeToFit() after adding content to your textContentView.
cell.textContentView.text = text
cell.textContentView.sizeToFit()
Make sure for sizing cell
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "onContentSizeChange:",
name: UIContentSizeCategoryDidChangeNotification,
object: nil)
tableView.estimatedRowHeight = 89
tableView.rowHeight = UITableViewAutomaticDimension
}
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
NSNotificationCenter.defaultCenter().removeObserver(self)
}
func onContentSizeChange(notification: NSNotification) {
tableView.reloadData()
}
Hope it helps you.
In conjunction with #Ashish Kakkad's answer you may want to try to set heightDimensions in viewDidLoad or viewWillAppear:
yourTableView.estimatedRowHeight = 30.0 // Put a real estimate here
yourTableView.rowHeight = UITableViewAutomaticDimension
Use auto layout code to tie the bottom of the cells contentView to the bottom of the text box. When the text box resizes it'll expand the cell with it.
This is in addition to Asish's correct suggestion about automatic cell heights and is quite a high level suggestion as you need to do a few things to get auto layout working right in tableview cells but there's ample examples on that out on the web.
oh, oh. Think I found something. I removed the existing contraints and then I've tried to "add missing constaints". The result was thas the error "Failed to automatically update constraints". Seem's I've a problem with my storyboard-file...

iOS8 - UITableView + Search Bar + custom view for the header

I have UITableViewController with UISearchBarController.
I'm trying to add a custom view between the table and the search bar like this:
First of all, in iOS8 (not sure if it the same in previous versions) SearchBar is added as UITableView's header and adding additional view to the header removes the SearchBar.
Secondly, it is not possible to add a custom view for the FIRST section using viewForHeaderInSection like this:
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
let view = UIView()
view.frame = CGRectMake(0, 0, 320, 100)
return view
}
return nil
}
The code above doesn't produce anything. However, if I return the same view for section == 1 then I get a view displayed
Does anyone know any solutions for this? I see the only way to solve this by skipping the first section and display all the cells starting from the second section

Resources