0

I am trying to show josn data and this happens

How can i prevent the ... from appering and show the full text?

Here is code

Here is Pic to show what is the problem Pic

As you can see there is the "..." and does not show full text

Any fix for this?

Thanks

    [{"url":"","description":"rferferferferferferferferferferferferferferferferfreferferferferferferferferfeerfeferferferf"},
{"url":"","description":"Image Description"},
{"url":"","description":"Image Description"},
{"url":"","description":"Image Descriprffttion"},
{"url":"","description":"Image Descriptijijion"},
{"url":"","description":"Image Description"},

{"url":"","description":"techavindu"},
{"url":"","description":"Image Description"},
{"url":"","description":"Imagesdaasdsd Description"},
{"url":"","description":"Image Descriprffttion"},
{"url":"","description":"Image Descriptijijion"},
{"url":"","description":"Image Dyubuyuubububububububuescription"},

{"url":"","description":"techavindu"},
{"url":"","description":"Image Description"},
{"url":"","description":"Imagesdaasdsd Description"},
{"url":"","description":"Image Descriprffttion"},
{"url":"","description":"Image Descriptijijion"},





]

 var json_data_url = "http://aliectronics.com.au/json_table_view_images%20(1).json"


    var isProgressShowing = true;

    var TableData:Array< datastruct > = Array < datastruct >()

    enum ErrorHandler:ErrorType
    {
        case ErrorFetchingResults
    }


    struct datastruct
    {

        var description:String?


        init(add: NSDictionary)
        {

            description = add["description"] as? String



        }

    }

    @IBOutlet var tableview: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = color125



        tableview.dataSource = self
        tableview.delegate = self

        get_data_from_url(json_data_url)
    }




    override func viewWillAppear(animated: Bool) {
        let barButtonItem = UIBarButtonItem(title: "Refresh", style: .Plain, target: self, action: "refreshTapped");
        self.navigationItem.rightBarButtonItem = barButtonItem;
    }



    func refreshTapped() {
        addProgressIndicator(isProgressShowing);
        get_data_from_url(json_data_url)

    }

    func addProgressIndicator(show : Bool) {
        isProgressShowing = !show;
        if(show) {
            let myActivityIndicator = UIActivityIndicatorView(activityIndicatorStyle:UIActivityIndicatorViewStyle.Gray)
            myActivityIndicator.startAnimating()
            let barButtonItem = UIBarButtonItem(customView: myActivityIndicator)
            self.navigationItem.rightBarButtonItem = barButtonItem




        } else {
            self.navigationItem.rightBarButtonItem = nil;




        }




    }




    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)

        let data = TableData[indexPath.row]


        cell.textLabel?.text = data.description



        return cell

    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return TableData.count
    }







    func get_data_from_url(url:String)
    {


        let url:NSURL = NSURL(string: url)!
        let session = NSURLSession.sharedSession()

        let request = NSMutableURLRequest(URL: url)
        request.HTTPMethod = "GET"
        request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData


        let task = session.dataTaskWithRequest(request) {
            (
            let data, let response, let error) in

            guard let _:NSData = data, let _:NSURLResponse = response where error == nil else {
                print("error")
                return
            }

            dispatch_async(dispatch_get_main_queue(), {
                self.extract_json(data!)
                return
            })

        }
        addProgressIndicator(!isProgressShowing);
        task.resume()



    }


    func extract_json(jsonData:NSData)
    {
        let json: AnyObject?
        do {
            json = try NSJSONSerialization.JSONObjectWithData(jsonData, options: [])
        } catch {
            json = nil
            return
        }

        if let list = json as? NSArray
        {
            for (var i = 0; i < list.count ; i++ )
            {
                if let data_block = list[i] as? NSDictionary
                {

                    TableData.append(datastruct(add: data_block))
                }
            }


            do_table_refresh()

        }


    }




    func do_table_refresh()


    {
        dispatch_async(dispatch_get_main_queue(), {
            self.tableview.reloadData()



            return
        })
    }









}
  • Are you looking for the text to wrap onto the next line? – InSearchOf Jan 27 '16 at 02:21
  • 2
    Please use as little code as possible that still produces the same problem. Avoid including code that is clearly unrelated to the question. –  Jan 27 '16 at 03:20

3 Answers3

2

You can do that using auto dimension for the cell of tableview. Kindly follow this url. He have mention about the textview. you can do same with label.

Change height of textview according to content

Waqas Sultan
  • 884
  • 5
  • 13
1

Assuming your text is in a UILabel, you can use adjustsFontSizeToFitWidth along the lines of:

myLabel.adjustsFontSizeToFitWidth = true

Have a look at the documentation here. Given that your using a UITableViewCell, you would do something like:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
    let data = TableData[indexPath.row]
    cell.textLabel?.text = data.description
    cell.textLabel!.minimumFontSize = 8
    cell.textLabel!.adjustsFontSizeToFitWidth = true

    return cell
}

I have also set the minimum font size above, so it doesn't get so small you can't see it.

Michael
  • 8,891
  • 3
  • 29
  • 42
0

You can change number of lines of textLabel to be displayed on tableview cell like given below. By setting it to "0" it'll display full text, no meter how long it is. And if you want fix lines and after that wrap the content. You can set digits other then 0.

   func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
    ....
    }
Dipak Kacha
  • 423
  • 2
  • 13