-4

I would like to make some words in the cell invisible or visible. This is my code below.

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? TableViewCell


    var dic = ar[indexPath.row]
    cell!.cell0.text = dic["date0"]

...

cell!.cell0.text has "Helloworld"

I need "Helloworld" for later so I can't get only "world" from dic["date0"].

I would like to make only "world" visible in the table view.

Is there anyone who can help me out? Thanks!

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Y.Hwang
  • 3
  • 3
  • Use attributed string. This can help you to define a range and colour for your text in different ways. See this for example https://iosdevcenters.blogspot.com/2015/12/how-to-set-use-multiple-font-colors-in.html – ares777 Dec 17 '18 at 14:09
  • Unfortunately, that link does not seem to be directly relevant to my question... – Y.Hwang Dec 17 '18 at 14:29
  • Actually you can split your strings or proceed with range... – ares777 Dec 17 '18 at 14:34

3 Answers3

-1

What you are looking for are Substrings.

let string = "Helloworld"

let beginningText = String(string.suffix(5)) //world
let endText = String(string.prefix(5)) //Hello

let start = string.index(string.startIndex, offsetBy: 1)
let end = string.index(string.endIndex, offsetBy: -3)
let range = start..<end

let middleText = String(string[range]) //ellowo

For more information, refer to this answer on a different question: Link

Justin Ganzer
  • 582
  • 4
  • 15
  • I can't save only "world" part in the cell!.cello.text. I have to send the whole text to other method(or function). I just want to make that part visible. – Y.Hwang Dec 17 '18 at 15:21
  • Is making a custom cell not a possible solution in your case? I would create a new class that extends UITableViewCell and give it a property in which you can store "Helloworld" or other values. – Justin Ganzer Dec 17 '18 at 15:51
-1

In the cell class you can so like so:

 var str = "Helloworld"// for example

 var splitString  = str.components(separatedBy: "Hello")

 self.label.text = splitString
ironRoei
  • 2,049
  • 24
  • 45
  • I don't have a variable "label" here – Y.Hwang Dec 17 '18 at 15:23
  • If you want to show something in a cell you need to put some outlets in the cell view. For example put a label in the cell connect it to the cell class and then you will get it like this: let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! SomeCellClass cell.label.text = "string" – ironRoei Dec 17 '18 at 15:27
-3

Check out isHidden

With isHiddem you can choose with a Boolean value if you want to show the text or not

https://developer.apple.com/documentation/uikit/uiview/1622585-ishidden

Gianmarco G
  • 353
  • 4
  • 9
  • I tried before like cell!.cell1.isHidden = true but I would like to make the text partially hidden – Y.Hwang Dec 17 '18 at 15:23