I'm sort of new to Xcode, so forgive me in advance for any obvious wrong things that I might write.
I'm trying to write something a bit simple using the UIWebView. I've already made it load upon the app's loading, but I can't seem to do anything else. What I want to do next is to make a button appear/disappear depending on the current URL. This is what I used to (try to) get the current URL:
NSString *currentURL = viewWeb.request.URL.absoluteString;
(I'm using this code in the ViewController.h file)
When I made the outlet (Ctrl+dragging), I named it viewWeb and I also went and labeled it viewWeb. But it doesn't seem to work and I don't know why.
Also, please don't just give me some code without explaining, because this is a bit frustrating and I want to understand it.
EDIT: Thanks, but I'm not looking for help on the disappearing button just yet (by the way, viewWeb is my UIWebView, not the button). I need help to detect an URL change to make the button disappear. Is there a webViewDidLoad or something similar? viewDidLoad isn't for this.
In the ViewController.h File, you only declare the property, like this:
#property (strong,nonatomic) NSString *currentURL;
Then you can set the value in the ViewController.m file.
maybe in the -viewDidLoad method in the ViewController.m file like this:
_currentURL = viewWeb.request.URL.absoluteString;
You can set the property of hidden or not of the button to show it selectively based on the url.
// URLString contains the URL based on which you would like to show/hide the button
if ([currentURL isEqualToString:URLString]) {
viewWeb.hidden = NO;
}
else {
viewWeb.hidden = YES;
}
Related
I am making a custom keyboard in xib, and the buttons' constraints are added and everything works fine. But in the console it says "Unable to simultaneously satisfy constraints.". And like "UIButton:0x7f8a38411b50.leading" and so on. But there are too many buttons here, I just don't know which button the console it talks about. Can I assign a identifier to button so I can know which button's constraint need to be fixed? By the way it's in a custom keyboard.
For the app:
You can use the View Debugger in the Xcode.
For information on the View Debugger you can go through the following link:
View Debugger Documentation by Apple
For the Keyboard Extension:
Write a category on UIButton and override the method: - (NSString *)description;
You can do something like this in your View Controller:
#implementation UIButton (ButtonDesc)
- (NSString *)description
{
return self.titleLabel.text;
}
#end
Here, I'm returning the text of the button. You can return a string that is made up of unique information like tag, background color, etc which will help you in identifying the particular button.
You might know where exactly the constraints are breaking. Put a break point there and write something like this in the console:
po 0x78f45ab0
where 0x78f45ab0 is the address of the button.
Hope this helps.
You can try with the property of UIButton which is call tag.
I would like to change my UIImageView I used as a background image on my parentViewController after my childView is loaded
in my viewDidLoad, I have this line, that pretty works :
self.parentViewController?.view.addSubview(myBackgroundImage)
I wish to change it while I got an event on app. But when I try again to change it by using the same line as above it doesn't work.
Anyone have a solution ?
I think it is a bad practice to access the view from another controller. I will suggest you to create separate method for this. Or may be just use IBoutlet for this, for example:
self.parentViewController?.myBackgroundImageView.image = UIImage("your_image")
UIButton enable not working after Xcode Update to Xcode 5.0.1.
self.btn.enabled = NO;
self.btn.hidden = NO;
Please suggest.
You should probably check the following in your project :
Checklist
Make sure that the button btn is connected to the relevant button in the xib in the Interface Builder.
Check whether the method where you put the two lines self.btn.enabled = NO; and self.btn.hidden = NO; gets called or not.
Try using self.btn.userInteractionEnabled = NO;.
Maybe, you're re-setting the enabled property to YES somewhere later in the code.
These points were all I could think of, tell me if it resolves your issue.
If you are using Xib file to build interface. Then make sure that IBOutlet is set for self.btn? If not, Then set IBOutlet for that. If you post your full source code for self.btn, Then i can help you more.
I am fairly new to objective-C and XCode.
I am trying to update a text label on the screen,
I call a function loadData in viewDidLoad, which works fine. I am trying to print a string that was generated in the loadData function.
After that string is generated, I use:
self.MyLabel.text=string;
But does not update.
I am using IBOutlet as well, I think it might be related to different threads but I am not sure.
Any help is appreciated.
Have you tried updating the label after the
- (void)viewDidLoad {
// call another method before assigning to retrieve the string here.
self.MyLabel.text=string;
}
Sometimes the way the UIViewController and IB setup will need you to set in after the viewDidLoad. Try NSLog(#"%#", self.MyLabel) at wherever you try to assign to see if its not null
Your statement is correct:
self.mylabel.text = #"Test";
So make sure, that the IBOutlet is correctly connected (filled grey circle).
Check also if the string contains the correct value.
I'm using Interface Builder to layout my app. I have a UITextView that contains some text, part of which is a URL that I'd like to make clickable (e.g. launches a browser). I've read up on how to do this and believe I'm doing it correctly, however while the URL appears blue/clickable, clicking it in the iPhone emulator doesn't work. Nothing happens.
My controller:
#interface FirstViewController : UIViewController <UISearchBarDelegate>
#property (nonatomic, retain) IBOutlet UITextView *review;
#end
In my implementation I #synthesize review; (and am able to manipulate the view's text, so don't think that's the issue).
In IB I have:
..then later when I go to set the text (and attempt to make URLs in the view clickable) I do:
self.review.text = content;
// My understanding is that this makes URLs clickable...
self.review.dataDetectorTypes = UIDataDetectorTypeLink;
...which displays something like:
...which really looks like it wants to work, however when clicking the URL nothing happens. What am I missing?
--UPDATE--
Tried adding self.review.editable = NO; in response to Dixit Patel's answer, but it didn't fix the issue:
self.review.text = content;
// My understanding is that this makes URLs clickable...
self.review.editable = NO;
self.review.dataDetectorTypes = UIDataDetectorTypeLink;
Check the "Selectable" and "Links" checkboxes in the textview Attributes Inspector:
The issue was that User Interaction Enabled wasn't checked at the bottom of the View section of IB's Attributes Inspector.