0

I have a table view cell that is used in a multilingual application. I used two different UITableViewCell in my storyboard for right to left and left to right applications but both of these UITableViewCells are linked to one file.

I used this because I do not want to load diffrent cells when text orientation is right to left or left to right.

Suppose that we have one label into each cell. In objective c we can assign this two label into one outlet. But in swift only one of them can be assigned. When I assign one of them the other one remove

How can we do this mechanism in swift too?

Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115

2 Answers2

0

not just make outlet of label.
use outletCollection.

normally set property of label is like:

  • cell.lbl.text = "Title"

need to do with this outletCollection is like:

  • cell.lbls.forEach{ $0.text = "Title" }
b m gevariya
  • 300
  • 1
  • 4
  • 12
-1

I think it would be a better solution to set the textAlignment of the cell depending on the current language:

Try get the language with

var pre = NSLocale.preferredLanguages()[0]

and depending on whether it is a latin (Germanic, romanic etc. ;-) or arabic language you set

cell.textLabel?.textAlignment = .Left
cell.detailTextLabel?.textAlignment = .Right

see How to get current language code with Swift? and Swift UITableViewCell Alignment

Regards Simon

Community
  • 1
  • 1
Simon
  • 454
  • 7
  • 18