2

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 enter image description here

enter image description here

enter image description here

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

Amith
  • 1,907
  • 5
  • 29
  • 48
  • So what is your question? – rocky Jan 08 '16 at 00:59
  • @rocky i have updated the question and sorry to mention the problem Thank you – Amith Jan 08 '16 at 05:11
  • Why my answer was deleted by @George Stocker. He even don't know swift language. – Abin Jan 21 '16 at 07:04
  • @Abin Joseph The answer is exactly what i want, Mr George has been deleted that is really not fair. I have post a question , got the exact answer then i shared my points to answered person, i think George have no rights to do this. – Amith Jan 21 '16 at 07:08
  • Where is the answer? Why did @George? delete it? – Kyle KIM Jul 15 '16 at 23:52

0 Answers0