Can't change view from WatchKit controller - ios

I added a bunch of WKInterfaceLabels to the storyboard, added them as IBOutlets in InterfaceController.h, and used the SetText method to set some text on them. However, I get no change on the view. The console gives the message "Unknown property in Interface description" for each label. How do I fix this?
In InterfaceController.h, I define the label as follows:
IBOutlet WKInterfaceLabel *hdate;
In InterfaceController.m, I set it's text as follows:
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
[hdate setText:#"blah"];}

Since the correct answer is in the comments of the question, I will just post it here again:
You can't create the IBOutlet in the .h file with just
IBOutlet WKInterfaceLabel *hdate
in brackets, I have to set them as properties.
(Credits to user3261697)

Change
IBOutlet
To
#IBOutlet
Or reconnect the label to the view.
In my case, it ran successfully.

Related

Can we have data/custom attribute for buttons in ios?

Hello there im basically from web development i have a requirement where i have to send a unique alpha numeric value from one view to another view on click of the button is their any way around we can set custom attribute or data attribute for buttons in Ios one like in htm5 ?
The easiest method is to subclass UIButton.
#interface MyButton : UIButton
#property (strong) NSString *myCustomData;
#end
#implementation MyButton
#end
You could also override the look of the button within this custom class to apply the same button style to all your buttons at once.

How do I pass data from a text field in Flipsideview to Mainview? ios 7 xcode5

I'm currently writing an iPhone app that needs to pass data from a text field on the Flipside view to the Main view when the user clicks the Done button. This is the last component of a project that I am working on.
I've tried including my MainViewController.h file on my FlipsideViewController.m file, and this doesn't work. I'm currently writing in the - (IBAction)done:(id)sender portion, something like
MainController._aTextFieldOnTheMainView.text = _aTextFieldOnTheFlipsideView.text;
but I always get this error: Property '_aTextFieldOnTheMainView' not found on object of type 'MainViewController'.
What am I doing wrong?
Change/remove your weak declaration of #property (weak, nonatomic) IBOutlet UILabel *aTextFieldOnTheMainView;. This causes the deallocation of the property when the flipsideview comes onto the screen.
hope this helps

Not sure how to setup view object and connect with IBOutlet code

I am trying trying to copy all of the functionality of this example app provided by Apple called AVCam: https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112-Intro-DontLinkElementID_2
I am 99% done with copying this code, but I just have one final problem. I have an IBOutlet statement that looks like this: #property (nonatomic, weak) IBOutlet MediaCapturePreviewView *previewView;
According to the Apple sample code, this outlet is supposed to be connected to a View object that has been placed on top of the normal/default view.
Here is a screenshot of what the Connections Inspector looks like in the Apple example:
You will notice that the IBOutlet called "previewView" has been connected to something called the "Cam Preview View".
Also, in this screenshot, you can see that I am able to select this View object by itself and that it shows a Referencing Outlet in it's connections inspector for the same IBOutlet and View Object:
My problem is that I cannot get the IBOutlet code to connect to this View Object. I have tried the normal behavior of clicking and dragging to make the connections but it just wants to create a new outlet. It will not let me connect to the outlet that I have already created.
I have been playing with this for 2 hours now and just can't get it to work like Apple's sample code.
Any help is greatly appreciated thank you.
In your .xib file, make sure that UIView class is assigned as AVCamPreviewView instead of UIView.
A few possible solutions:
Save the file with the IBOutlet you're trying to connect up (the source code, not the IB)
Clean, rebuild
Restart Xcode.

Change content in UITextView

Quite a simple one I assume but searching has failed me.
I have a UITextView I set up in a Storyboard with some dummy text. Dynamically I would like to change the content of this, but I don't know how. Searching for this seems to only returns results in which the UITextView has been created programmatically as opposed to via a drag and drop on the Storyboard, hence they have direct access to a variable representing it.
Add an outlet to UITextView then changed it dynamically!
Like this:
#property (weak, nonatomic) IBOutlet UITextView *yourText;
self.yourText.text = // ANY TEXT HERE

UITextView setText is not updating the text

In my nib, I have a UITextView component.
In my code I have a UITextView field and I have used Interface Builder to make sure that the two are connected (at least I think I did that by dragging from "Files Owner" and dropping it on the UITextView in Interface Builder and selecting my member variable).
Now, when I update the text via setText, the UITextView still remains blank.
Thanks
DeShawn
Have you used
#property(nonatomic,retain) UITextView *yourTextViewName;
then
#synthesize yourTextViewName;
in .m file?
If yes, use the following code in viewDidLoad after updating the value to check:
NSLog(#"Text View Value = %#",yourTextViewName.text);
If it isn't figured it out yet;
check out iOS Text View Not Updating
The referencing yourTextViewName must be an IBOutlet UITextView *yourTextViewname
Then add the #property (nonatomic, retain) UITextView *yourTextViewName.
Add the #synthesize yourTextViewName in the corresponding .m file.
To set the text, use
yourTextViewName.text = #"some text";
This may sound crazy, but I had to explicitly set the hidden property of UITextView to NO in code and then it started showing up. See if this works for you.

Resources