retrieve the text of WKInterfaceLabel in swift

我们两清 提交于 2019-12-08 15:45:22

问题


How can i get the text of label in Swift or Objective-C in WatchKit?
The class is not UILabel but it is WKInterfaceLabel.
I have also tried to search in class library of apple but there is only three methods are available.


回答1:


By reading reference it is not possible you have to maintain track which you set in label
looks like apple is very strict about this class you can not create a subclass or direct instance of this.


They only talk about how to set the text not about getting text


Non of it's supper class have method to get text


If its posible You can create extension of WKInterfaceLabel and get text
but no idea if apple approve it or not.

My Conclusion is
Its not possible directly by any way to get text
you can do some trick but make sure that its acceptable by apple.


Friendly speaking i am not much aware about watch SDK, but if you dealing with any beta version of type thing let hope that apple will add that thing in new version as they had wrote


Reference of all i wrote and images are here


回答2:


Just have a @property (nonatomic) NSString *currentText; That everytime you update or set your WKInterfaceLabel you also set or update.

It's not the best solution, but it works for now, while Apple doesn't have any official way to get it.




回答3:


Apple has declared WKInterfaceLabel class with only setter property and no getter property.

This screenshot shows class declaration of WKInterfaceLabel present in WatchKit framework.



来源:https://stackoverflow.com/questions/27456160/retrieve-the-text-of-wkinterfacelabel-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!