You can't add random data to views. You can subclass UIView if you want and add a property to the class and store your string there. Or you could make a property in the ViewController that is driving your UIVIew and assign the string to it.
Using a data structure? [closed]
-
13-10-2022 - |
Question
Currently I have a view UIView *myView;
. I would like to add data to the view by saying something like myView.stringdata = @"whatever";
. How can I do this?
Sorry for the simple question I'm new to Xcode.
Solution
OTHER TIPS
You cannot add data to an instance of a class if the class does not have an ivar + accessor or a property for it.
You need to use one of the following approaches:
Subclass Category Delegate Associative Objects Composition Collections
All of these involve modifying the class as a whole in your app (or any app if it were a framework class in a framework visible at the user or system level) or they involve creating new classes or association by being in collection member.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow