I am very new to Mac development, I wish to create a chat application in OS X using swift language, I am using NStableView to display the messages, The height of the table row should be wrap according to the text size just like the following images
As we can show the text will wrap according to window resizes.
my code is follows
import Foundation
import Cocoa
class ChatWindowVC : NSViewController,NSTableViewDataSource,NSTableViewDelegate{
@IBOutlet var tableView: NSTableView!
private var arr = [String]()
@IBOutlet var message: NSTextView!
private var hgt:CGFloat = 20
@IBAction func send(sender: NSButton) {
if let textStorage = message.textStorage{
if !textStorage.string.isEmpty{
let str = textStorage.string
arr.append(str)
// textStorage.mutableString.setString("")
tableView.reloadData()
}
}
print("Send.....\(message.textStorage?.string)")
}
override func viewDidLoad() {
super.viewDidLoad()
arr.append("ONE")
arr.append("TWO")
arr.append("THREE")
}
func numberOfRowsInTableView(aTableView: NSTableView) -> Int
{
let numberOfRows:Int = arr.count
return numberOfRows
}
func tableView(tableView: NSTableView, objectValueForTableColumn tableColumn: NSTableColumn?, row: Int) -> AnyObject?
{
return arr[row];
}
func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? {
let result : ChatCell = tableView.makeViewWithIdentifier("ChatCell", owner: self) as! ChatCell
result.sent.stringValue = arr[row]
return result
}
func tableView(tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
let str = arr[row]
let c:Int = str.characters.count
let cgfloat = CGFloat(c)
print(cgfloat)
return cgfloat
}
}
Please guide me
my problem is i could not set the row height according to the window resize
The attached screen shot is an example of my target
It would be great if you can give an example or code snippet
Thanks a lot
Amith