Objective-C - Making an image link - objective-c

The thing is that I'm rather new to Objective-C and have been reading about it now for a few days online. I started to create a simple iOS application but I didn't find anything about this when I Googled it.
Now I want to create a link that is not plain text, but an image.
If this is incomprehensible, then this is how I would do it in HTML:
<img src="IMAGE.png"/>
So far in my ViewController.h, I have:
-(IBAction)link;
And in my ViewController.m, I have:
-(IBAction)link {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com/"]];
}
How would I link this URL to an image?
Cheers.

There's a simple way to do that. You can add a button on top of the image and make the button send actions to the view controller, or you can link it to -(IBAction)link; directly.

Add a UIButton in IB/Storyboard to your view.
Make that button of the same size that your image is.
Assing the image as the buttons image or background image.
Connect the touch up inside event with the IBAction link.
Or do you want to do that programmatically?

Related

Creating segue from UIImageView to other viewcontroller programatically

I have created few thumbnails of images dynamically and i want to display detail description about that image in other viewcontroller when the respective image is clicked. I am using Storyboard (universal) in Xcode 4.6.
I am new to Xcode can anyone suggest me how to create segue for transitioning to new View Controller when the image is clicked or tapped
Any suggestions or examples will be appreciated.
Thanks in Advance.
Edit:
I am not able to get the click on the uiimageview which is subview of the uiscrollview and the images are created dynamically.
Also wanted to know that is there a way by which i can come to know which image is being clicked.

Prototype button in StoryBoard?

My app dynamically generates buttons. When the button is clicked it creates a table linked to it. I have all the table interfaces (navigation controllers, etc.) set up in storyboard. However, my main view is the home screen where the user creates buttons. Since the button isn't already there, how do I set it up so that it creates a new instance of the tableview outlined in my main storyboard? Is there a "prototype button" in storyboard? The "#selector" action for the generated button is pointing to this IBAction:
-(IBAction)generateTable:(id)sender {
}
Can someone help me fill in the remaining code?
Also, the home screen view controller is already set up in Storyboard, with the arrow next to it.
EDIT: this picture might help understand my problem a better.
http://i.imgur.com/MdT4i1P.png
Found the answer myself quite easily. All you have to do is make a segue (with an identifier) in Storyboard from your ViewController to the ViewController you want it to connect to, then in the IBAction, just add the following.
-(IBAction)generateTable:(id)sender
{
[self performSegueWithIdentifier:#"GoToTable" sender:sender];
}

How to hide or remove the UIwebview when a action is done?

I have two IBActions. In one action I am loading the UIWebview to display a PDF File from my bundle. On clicking the other button the whole UIWebView should get removed from superview.
I have tried using:
[webview removeFromSuperview];
and
webview.hidden=YES;
Neither of these are working. They are hiding my UIWebView for a second, but then it appears again.
Is is
I have created UIWEBVIEW programatically and added the UIWebvieWDelegate in the interface file. But when initializing the UIWebView I didnt set webview.delegate=self; Is it the problem?
have you connected Referencing Outlet to the class's #property in the Interface Builder?
If you don't do it, it would be the a possible reason why you cannot reach the UIWebView in your source code. for your sake, you should check the pointer of webview, if it is nil chronically, there is 100% you have not connected them each other.
I was trying to make a thing like this. The solution that worked for me was to add UIview object as subview to view with the frame of webview and bringing it to top.... When u want to make uiwebview visible, just remove that uiview object from superview.
OK, it seems old question, but also i can see there are almost thousand people have view it, and may have the same problem. so my answer for anyone my have the same issue in the future.
I just been doing something smiler and want to hide the web view when at a certain action.
I have tried the following
-(void)viewDidLoad
{
[super viewDidLoad];
process = [ProcessingData new];
[DetailView setHidden:YES];
DetailView.hidden = YES;
[DetailView removeFromSuperview];
self.DetailView = nil;
}
however it is still not working, as i have few labels in the WebView which are don't disappear when the view load, when I looked at the "StoryBoard" i notes that the labels are not subview of the
can u see the hierarchy of the libels under the WebView, they are subview of the main view, where they suppose to be same as the table view hierarchy
so in may case the WebView is hiding but the labels are not as they are not a part of the Webview.
how to sort this problem, if you really don't need web view use the normal one, otherwise you have to hide all the labels in that view. hope thats helpe
I don't know obj-c but still posting a solution that worked for me in swift. basically you have to use the main thread to remove the webview.
DispatchQueue.main.async {
print("\nremoving webview\n")
self.myWebView.stringByEvaluatingJavaScript(from: "document.body.innerHTML='';")
self.myWebView.removeFromSuperview()
}

UIImageView in PopOver not changing?

I'm making an app and it has multiple button that when you press them it open a pop over view (using Storyboard.) The image is blank in IB (I set it that way) and my buttons are ment to populate the image view. This is the code I'm using:
[popoverImageView setImage:[UIImage imageNamed:#"telegraph.jpeg"]];
Steps (in order run)
Popover opens
Above code is run
Some notes:
The image is case matched.
The image is built-into the bundle
Anyone able to shed some light?
if you haven't read Apples View Controller Catalog for iOS you should read it.
I would check your popoverImageView's viewDidLoad/viewWillLoad and see if it is clearing your View before it presents itself.
Check your popoverImageView's properties they may not be linked properly
Enjoy using the storyboard I find it a pain for Popover's
Without any information regarding the the interface for your Popover and the implementation of the function where you call [popoverImageView setImage:[UIImage imageNamed:#"telegraph.jpeg"]]; and your setImage function i can't be sure of your exact problem

Replicate apple's mailComposer UITextView?

I want to replicate apple's default mail composer for my app. I don't want to use default mailcomposer because I'm having a lot of other things. Does anybody have solution for this? Main thing I want to implement is attachments. Like when you select a image and tap on email on photos app. The image preview is displayed in body part and also we can enter text and the cursor also detects the image when you press return or back. That functionality I want to achieve.
The TTMessageComposer in the Three20 library is a good start... it doesn't have attachment support but will save you time on the standard layout.
Three20 library
Check out this source code https://github.com/thermogl/TITokenFieldView, it's a custom UI class for token fields but there is a exact replica of Apple's mail UITextView. Heres a snippet from the source. All you have to do is create an normal text view and add it to your view.
// Creating the text view
messageView = [[UITextView alloc] initWithFrame:yourView.contentView.bounds];
// Adding it as a subview
[yourView.contentView addSubview:messageView];
// Set the frame so it resizes with the view.
[messageView setFrame:yourView.contentView.bounds];