4

I have a view controller in storyboard, and combining UILabel and ui collection view together in the controller. However every time I change the UILabel text, it will trigger auto layout, which shows I got view will layout and view did layout events. I don't want changing text to trigger auto layout. But When I use self.XCategoryLabel.translatesAutoresizingMaskIntoConstraints = NO;

It does not work.

How can I make UILabel text changing not trigger auto layout? I do use auto layout in this controller, but I DONT want the label to trigger it.

Wingzero
  • 9,644
  • 10
  • 39
  • 80
  • Why don't you want the label to trigger it? Is the laying out doing something to your collection view? – rdelmar Feb 10 '15 at 02:30
  • I have some touch events with another view, enabling user to pan and drag, and when using this label, every time I update the dataSource for UICollectionView, I will change the label as well. However if the label triggers auto layout, the touch events will break, not smooth – Wingzero Feb 10 '15 at 02:39
  • Well, I don't think it's possible when using auto layout to not have the label trigger those methods when you set the string. How are you doing your pan? Are you moving the view using constraints or setting frames? Is that view using auto layout? – rdelmar Feb 10 '15 at 02:41
  • I use auto layout for the skeleton views, but some views are created by code inside the skeleton views. when user drag or pan, the data is changing, so it will update you very smooth. However If I use this label, it will trigger the view will layout and view did layout events, so it will interrupt the gesture. I am thinking if I add this label inside a view will help? – Wingzero Feb 10 '15 at 02:43
  • I don't know if that will help. Go ahead and try it (but I'm skeptical that it will work). You didn't answer my other question. Are you moving your skeleton view by modifying constraints or setting new frames? – rdelmar Feb 10 '15 at 02:49
  • No views are changing. Think about I have a stock market app, there is a chart showing the stock price line in one day, and a collection view showing its price at every clock. And the label as the time. When user move to 2p.m, it will show 2.p.m stock price, but the views will not change. only data changed – Wingzero Feb 10 '15 at 02:51
  • and I tried, it does not work. I also tried if I create the label by code, not dragging a UILabel in storyboard, still no luck – Wingzero Feb 10 '15 at 02:54
  • "How can I make UILabel text changing not trigger auto layout? I do use auto layout in this controller, but I DONT want the label to trigger it." Then you're doing it wrong. You need to set up your constraints so that triggering layout is okay with you. It can happen at _any_ time. You are not in charge. – matt Feb 10 '15 at 02:59
  • Triggering auto layout event will break my user interaction when user pans with another view. if I do not use this label, the data refreshes very smooth when panning, but when change this label text, it will break. I am frustrated. – Wingzero Feb 10 '15 at 03:01
  • and I also have other labels inside the collection view cell, but they did not trigger will layout and did layout. only this label will. This label is on the top of this collection view. – Wingzero Feb 10 '15 at 03:02
  • What the f***... I comment out `self.XCategoryLabel.translatesAutoresizingMaskIntoConstraints = NO` and it solved my problem! – Wingzero Feb 10 '15 at 03:23

1 Answers1

3

I add a view in Storyboard, and add constraint to it. Then I add the UILabel into this view by code, and NOT setting Label.translatesAutoresizingMaskIntoConstraints to NO.

Then It will not trigger viewDidLayout and viewWillLayout.

Wingzero
  • 9,644
  • 10
  • 39
  • 80
  • this is not the perfect solution, but it did solved my problem. The reason I add a container view for the label, is trying to isolate UILabel with other views. You could try directly add UILabel in the storyboard, and add proper constraint, and not set `translatesAutoresizingMaskIntoConstraints` to NO. to see how it works – Wingzero Feb 10 '15 at 03:31