Can't make URL clickable in UITextView - ios

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.

Related

Can I assign a identifier to my button so I can know which button's constraint is wrong in console

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.

IBOutlet Visible after successful login, Objective C

So i have a tableView that shows some information that i parse from the web. I also have a DetailViewController that shows additional information about the cell that the user clicks on.
Now I'm using a TabBarViewController and on the last tab bar i want to have a login section. If the user is logged in he/she will be able to change the information stored in the DetailViewController (there will be some UIButtons and some UILabels the user will be able to push and insert some text to.)
I tried to search on the web just as the title for this question has but I didn't find anything at all. So please if you could provide me maybe a name for this technique so i can look it up or even links for tutorials would be better. Any tips and suggestions would also be great!
BTW I'm thinking about using NSKeyChains (maybe other suggestions here?)
So,
You have to link each element you want to show/hide in your UIViewController with an IBOutlet:
#interface YourViewController ()
#property (nonatomic, weak) IBOutlet UILabel *yourLabel;
#property (nonatomic, weak) IBOutlet UIButton *yourButton;
#end
And you can have a method to display/hide those elements depending if the user is logged or not, like this:
- (void)showOrHideButtonsDependingOnLoggedState()
{
BOOL logged = // some method to discover if he/she is logged
if (logged) {
_yourLabel.hidden = NO; // depending if you to show or hide
_yourLabel.hidden = YES;
} else {
_yourLabel.hidden = NO;
_yourLabel.hidden = YES;
}
}
and call it before your view appear or when the logged state changes.
If you have some confidential information about the user and want to have a secure place to store that, you are right about storing it inside the Keychain. There are a few libraries you can use to avoid the pain of store/loading it by your own. One of them is that: https://github.com/danielalves/NitroKeychain
You can use 2 containers in your storyboard. One would be the login view controller, the other one would be your DetailViewController.
Then you just have to hide the login view controller is the user is already logged in.
This tutorial might help you
Or you can also just present the login view controller modally so that the user is forced to login to acces the DetailViewController.
See Apple's reference

Getting URL of UIWebView

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;
}

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