PDA

View Full Version : UIWebView ~ Linking a button??




alexpja
Jan 20, 2011, 05:32 PM
Hi there, I am making a newsreader application where I want to have a button on the toolbar on the bottom of my screen to take me back to my website... how can I do this? :confused: I have the back, forward, refresh, and stop buttons all good and working, just need this button :/



hayesk
Jan 20, 2011, 05:36 PM
What problem are you having?

Add a button, set the target and action to a method on your view controller that tells your web view to load the URL of your home page.

alexpja
Jan 20, 2011, 05:37 PM
What problem are you having?

Add a button, set the target and action to a method on your view controller that tells your web view to load the URL of your home page.

Here's the problem... I am a total newbie and do not like to read books, and cannot find anything like this on Google :S so I'd love any help I can get o_o

alexpja
Jan 20, 2011, 06:26 PM
What problem are you having?

Add a button, set the target and action to a method on your view controller that tells your web view to load the URL of your home page.

What did he mean... D:

dejo
Jan 20, 2011, 06:26 PM
Here's the problem... I am a total newbie and do not like to read books, and cannot find anything like this on Google :S so I'd love any help I can get o_o
First, of all: welcome! we were all newbies at some point. There's nothing wrong with that.

If you ask for specific help, you'll get more support. Just realize that probably very few here are going to just give you a solution you can copy-and-paste.

If you don't like to read books, fine. But if you want to become a good programmer, you're going to want to be comfortable reading, because it will be quicker for you to be able to find and interpret pre-existing information rather than seeking help from others constantly. Just some advice as you start out.

So, if books aren't for you, what is? That will help us tailor our answers to an approach you prefer.

alexpja
Jan 20, 2011, 06:31 PM
...
So, if books aren't for you, what is? That will help us tailor our answers to an approach you prefer.

Well, I am making an app where you can view through a selection of websites to read, and I need a button on the toolbar where the back, forward, refresh, and stop buttons are to link back to the original website where they can go through the selection again without having to press back too much... I need a simple, copy-n-paste code since I will not be able to combine this piece of code, and this piece of code to make this piece... etc. e.e

dejo
Jan 20, 2011, 06:34 PM
I need a simple, copy-n-paste code since I will not be able to combine this piece of code, and this piece of code to make this piece... etc. e.e
Well, good luck with that!

alexpja
Jan 20, 2011, 06:36 PM
Well, good luck with that!

o_o That's helpful e.e

dejo
Jan 20, 2011, 06:39 PM
o_o That's helpful e.e
Sorry, I couldn't be more helpful but I wanted to wish you well in your quest. I suspect you're gonna need it. ;)

alexpja
Jan 20, 2011, 06:40 PM
Sorry, I couldn't be more helpful but I wanted to wish you well in your quest. I suspect you're gonna need it. ;)

Of course I am... since there is no one who can help me with this :/ Can you? o:

dejo
Jan 20, 2011, 06:45 PM
Can you? o:
Perhaps. As you can tell, I'm not about to give you copy-and-paste code. As robbieduncan likes to say, "That's not programming". But if there is some other approach to learning besides books that you prefer, please let us know and we'll see what we can do.

Also, make sure you've stopped by the Guides and Stickies at the top of this very forum (http://forums.macrumors.com/forumdisplay.php?f=135).

alexpja
Jan 20, 2011, 06:46 PM
Perhaps. As you can tell, I'm not about to give you copy-and-paste code. As robbieduncan likes to say, "That's not programming". But if there is some other approach to learning besides books that you prefer, please let us know and we'll see what we can do.

Searched through Google, found nothing... Will look at that sticky... Thanks anyway v.v

EDIT:

If I'm understanding your problem correctly, you want each of the buttons on the left to cause the web view on the right to load a particular URL. If that's the case, one reasonable way to do that is to create a view controller for this view (you may have done that already) which has an action (or actions) to which you would connect each button.

The view controller would have an outlet to the web view so it can send messages to that view to load URLs as needed.

Assuming I'm understanding the question correctly...

This is what I meant... except I do not know what the view controller is and I do not know how to work with it, I know how to make actions and outlets though...

dejo
Jan 20, 2011, 09:45 PM
...except I do not know what the view controller is...
If you don't know what a view controller is I think it's time to step away from the real coding and go learn the basics of iPhone programming. Without a good foundation of the fundamentals, it is going to be more difficult to move forward with even fairly simple tasks like you are attempting to do. In other words, you must learn to walk before you can run.

alexpja
Jan 20, 2011, 11:01 PM
If you don't know what a view controller is I think it's time to step away from the real coding and go learn the basics of iPhone programming. Without a good foundation of the fundamentals, it is going to be more difficult to move forward with even fairly simple tasks like you are attempting to do. In other words, you must learn to walk before you can run.

Okay e.e.... Now where can I find the basics of iOS programming that are simple enough for someone like me (I do not even understand the iOS Reference Library).... e.e

dejo
Jan 21, 2011, 01:52 AM
Well, you still haven't told us what learning style you prefer (all we know is what you don't like: books), so it's hard to make recommendations. Was there nothing in the FAQ that appealed to you?

alexpja
Jan 21, 2011, 07:20 AM
Well, you still haven't told us what learning style you prefer (all we know is what you don't like: books), so it's hard to make recommendations. Was there nothing in the FAQ that appealed to you?

The learning style I prefer is more like... online tutorials that are understandable and easy to learn from... not like the iOS reference library :S

In the FAQ (which I think you meant is the guides and stickes on top of the forum), there was nothing that appealed to me... and also, I am trying to get this done as soon as possible so :S and sorry for any misunderstandings when reading my replies, Polish is my first language :3

Also, with books (I read books all the time, just hate them for learning resources) I cannot concentrate on what I am reading and it is harder for me to follow with what the book says...

dejo
Jan 21, 2011, 08:53 AM
The learning style I prefer is more like... online tutorials that are understandable and easy to learn from... not like the iOS reference library :S

In the FAQ (which I think you meant is the guides and stickes on top of the forum), there was nothing that appealed to me... and also, I am trying to get this done as soon as possible so :S and sorry for any misunderstandings when reading my replies, Polish is my first language :3
The iPhone Developer FAQ (http://forums.macrumors.com/showthread.php?t=518968) (which is a Sticky of this forum) contains a link to some online tutorials. Did you give them a look? Also, I've found the iCodeBlog tutorials (http://icodeblog.com/category/tutorials/) to be quite helpful (although the oldest articles on the simplest things may be somewhat out-of-date now).

As for trying to get this done as soon as possible, what is the reason behind the urgency? Do you have a deadline or something?

nickculbertson
Jan 21, 2011, 09:11 AM
in your .h

- (IBAction)mySite;


in your .m

- (IBAction)mySite {
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com"]]];
}



add a bar button item in interface builder and connect it to mySite action.

Nick

alexpja
Jan 21, 2011, 03:46 PM
in your .h

- (IBAction)mySite;


in your .m

- (IBAction)mySite {
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com"]]];
}



add a bar button item in interface builder and connect it to mySite action.

Nick

Thank you so much! Thanks for helping me... :D

EDIT: Should I place it between:

@interface WebAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UIWebView *webView;
}
? (.h) and where in my .m?

As for trying to get this done as soon as possible, what is the reason behind the urgency? Do you have a deadline or something?

Yes.

Cromulent
Jan 21, 2011, 03:54 PM
Yes.

If it is homework you should say so. If you are being paid to do it you should sub-contract it out.

alexpja
Jan 21, 2011, 04:16 PM
If it is homework you should say so. If you are being paid to do it you should sub-contract it out.

Yes its homework... o.o

dejo
Jan 21, 2011, 04:56 PM
Yes its homework... o.o
Well, you should be very thankful that nickculbertson did half your homework for you. :)

alexpja
Jan 21, 2011, 05:41 PM
Well, you should be very thankful that nickculbertson did half your homework for you. :)

I am. I need to figure out where to put the code :S

dejo
Jan 21, 2011, 05:48 PM
I am. I need to figure out where to put the code :S

How did you get the "back, forward, refresh, and stop buttons all good and working"? Maybe try the same approach?

alexpja
Jan 21, 2011, 06:52 PM
How did you get the "back, forward, refresh, and stop buttons all good and working"? Maybe try the same approach?

Well, I went into IB, and pressed the button. Then, CTRL-clicked the UIWebView, and clicked the action for that button. I cannot do that for my button, so please just help me here and stop pointing me to FAQs and tutorials when they will not help my problem e.e

chown33
Jan 21, 2011, 08:15 PM
Well, I went into IB, and pressed the button. Then, CTRL-clicked the UIWebView, and clicked the action for that button. I cannot do that for my button, so please just help me here and stop pointing me to FAQs and tutorials when they will not help my problem e.e

If it's homework, which is what you told us earlier, aren't you supposed to know how to do this yourself?

You're basically asking for someone to do your homework for you, which you will then hand in and get credit for in whatever class you're taking. When I was in school, that was called cheating.

You're not only asking for help in cheating, you're being impatient about not getting the answers you seem to feel entitled to, instead of applying yourself to studying how to do it yourself.

alexpja
Jan 22, 2011, 01:30 AM
I just need to finish this and I'll be gone, just please help me ._.

alexpja
Jan 23, 2011, 11:09 PM
I have added a button, but still cannot figure out where to put the code nickculbertson gave me...

dejo
Jan 23, 2011, 11:29 PM
I have added a button, but still cannot figure out where to put the code nickculbertson gave me...

Talk to your teacher; tell them you are having problems with this assignment. Maybe they'll provide some needed guidance.

P.S. What school are you going to and what class are you taking?

alexpja
Jan 24, 2011, 03:24 PM
Talk to your teacher; tell them you are having problems with this assignment. Maybe they'll provide some needed guidance.

P.S. What school are you going to and what class are you taking?

I do not think asking my teacher to help me is a wise idea... also it is not public school, more like a private course I took because I am interested in iOS programming...

dejo
Jan 24, 2011, 03:44 PM
I do not think asking my teacher to help me is a wise idea...
Why not?

...also it is not public school, more like a private course I took because I am interested in iOS programming...
Does that matter? You are taking a class to be educated in something. If you are not understanding something, I think you should be able to approach the instructor to have them perhaps try a different approach in order for you to be educated.

P.S. Why do you think it's not okay to ask your teacher for help, but asking us to help you cheat on your homework is okay?

alexpja
Jan 24, 2011, 05:30 PM
Why not?


Does that matter? You are taking a class to be educated in something. If you are not understanding something, I think you should be able to approach the instructor to have them perhaps try a different approach in order for you to be educated.

P.S. Why do you think it's not okay to ask your teacher for help, but asking us to help you cheat on your homework is okay?

Why not? Well because he expects us to learn what he teaches us, and the way he teaches confuses me...

@PS Well, I am asking for help, and I am not cheating... this forum is so unhelpful...

dejo
Jan 24, 2011, 05:44 PM
Why not? Well because he expects us to learn what he teaches us, and the way he teaches confuses me...
He may not be aware that his way is confusing you but may be willing to try a different approach if he's informed of it. If you still can't learn it, perhaps you should get a refund on your class.

@PS Well, I am asking for help, and I am not cheating...
The help you are asking for is for others to solve a homework assignment for you, which you will then hand in as your own work. That's cheating.

...this forum is so unhelpful...
nickculbertson gave you a lot of the answer. Based on your skewed perception of "help", I'd say that was pretty helpful.

alexpja
Jan 24, 2011, 06:03 PM
nickculbertson gave you a lot of the answer. Based on your skewed perception of "help", I'd say that was pretty helpful.

He gave me the actual code, but didn't tell me where to place it.

Code: 1/2
Where to place it: 1/2

His help = 1/2

dejo
Jan 24, 2011, 06:07 PM
He gave me the actual code, but didn't tell me where to place it.

Code: 1/2
Where to place it: 1/2

His help = 1/2
So, according to you:

His help = "so unhelpful".

When you should consider half the answer pretty darn helpful, considering you're supposed to be figuring this out on your own.

alexpja
Jan 24, 2011, 06:46 PM
So, according to you:

His help = "so unhelpful".

When you should consider half the answer pretty darn helpful, considering you're supposed to be figuring this out on your own.

I am considering the half of the answer helpful, I have tried to put the code but failed... which is why I am asking.

dejo
Jan 24, 2011, 06:59 PM
What have you learned about the structure of an Objective-C class and where to put (instance variables, properties and) instance methods in the header file and then their corresponding pieces in the implementation file?

alexpja
Jan 24, 2011, 10:11 PM
What have you learned about the structure of an Objective-C class and where to put (instance variables, properties and) instance methods in the header file and then their corresponding pieces in the implementation file?

Well I do not really remember since it is 10:12 and I have the worst memory ever... somewhere in my notes in my backpack.

nickculbertson
Jan 24, 2011, 10:23 PM
Well, I went into IB, and pressed the button. Then, CTRL-clicked the UIWebView, and clicked the action for that button. I cannot do that for my button, so please just help me here and stop pointing me to FAQs and tutorials when they will not help my problem e.e

watch this
http://www.youtube.com/watch?v=B7jB0D3Y7Ws

then this
http://www.youtube.com/watch?v=jUbnUFWIZgI&feature=channel

This should show you how to add an action to a button.

dejo
Jan 24, 2011, 11:20 PM
Wirelessly posted (Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5)

What have you learned about the structure of an Objective-C class and where to put (instance variables, properties and) instance methods in the header file and then their corresponding pieces in the implementation file?

Well I do not really remember since it is 10:12 and I have the worst memory ever... somewhere in my notes in my backpack.

You should probably quit this course, if you still can, since you don't seem to have the drive or ambition to do the most basic things (like looking up information you already have) in order to succeed.

alexpja
Jan 25, 2011, 04:52 PM
You should probably quit this course, if you still can, since you don't seem to have the drive or ambition to do the most basic things (like looking up information you already have) in order to succeed.

No, I will not quit the course... and I've been asking for help since Friday... so just forget it. Just help me and stop telling me what to do... I just want to finish this.

dejo
Jan 25, 2011, 05:08 PM
...so just forget it.

Done!

alexpja
Jan 26, 2011, 02:13 PM
Done!

Fine... be like that.

nickculbertson
Jan 26, 2011, 02:23 PM
Fine... be like that.

Go... to youtube.... now...... learn

alexpja
Jan 27, 2011, 03:52 PM
watch this
http://www.youtube.com/watch?v=B7jB0D3Y7Ws

then this
http://www.youtube.com/watch?v=jUbnUFWIZgI&feature=channel

This should show you how to add an action to a button.

Not what I meant...
I know how to add an action to a button, I do not know where to put:
- (IBAction)mySite; and - (IBAction)mySite {
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com"]]];
}...

nickculbertson
Jan 27, 2011, 05:09 PM
Not what I meant...
I know how to add an action to a button, I do not know where to put:
- (IBAction)mySite; and - (IBAction)mySite {
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com"]]];
}...

Don't know what to tell ya. Those videos tell you where to place codes that are almost identical.

alexpja
Jan 28, 2011, 06:00 PM
Don't know what to tell ya. Those videos tell you where to place codes that are almost identical.

Will look at them, thanks.

alexpja
Mar 18, 2011, 06:24 PM
watch this
http://www.youtube.com/watch?v=B7jB0D3Y7Ws

then this
http://www.youtube.com/watch?v=jUbnUFWIZgI&feature=channel

This should show you how to add an action to a button.

My app is not a view-controller app, but (iirc) navigation-based... Help DX

EDIT:

Hello! I've been looking for a way to get a button that is pressed to load a page in the webview and I found this:

UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];

NSString *urlAddress = @”http://www.example.com”;

NSURL *url = [NSURL URLWithString:urlAddress];

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

[webView loadRequest:requestObj];

Now, the question is, where do I put it? :eek:

Also, would this work if I had a text box to enter a URL and press return and send it to the webview?

kingofwburg
Mar 26, 2011, 11:05 AM
.h


@interface appName : UIViewController {

}

-(IBAction)mySite;

@end


.m


@implementation appName

-(void)ViewDidLoad {

[super viewDidLoad];
}


-(IBAction)mySite{
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.website.com"]]];
}

dejo
Mar 26, 2011, 05:10 PM
kingofwburg, you sure you want to do someone else's homework for them?

kingofwburg
Mar 26, 2011, 11:27 PM
kingofwburg, you sure you want to do someone else's homework for them?

I hate seeing people floundering about. Plus, it might mean an end to the thread. If they can't figure out what to do from this point, it's truly hopeless.

jnoxx
Mar 27, 2011, 06:26 AM
Like Dejo pointed out, if you are just here for copy/pasting, instead of at least reading trough some basics, which shouldn't take u longer then 2 hours or so.
I don't think this is the right attitude towards forum users, who are here to try to help u. Not to help you, because u demand it.
Well, we can even show u how to do the code, but if u don't know what viewControllers are, or how to link stuff in IB. Then that's where it stops, read through the basics, can't really say more. Or quit ur class, and do something else.

(Sorry Dejo if this is offensive, but this made me crazy)

LinkMx
Mar 27, 2011, 06:42 PM
What's the point in taking a programming class if you want someone to do the work for you? It seems like a waste of money and time.

dejo
Mar 27, 2011, 07:09 PM
Like Dejo pointed out, if you are just here for copy/pasting, instead of at least reading trough some basics, which shouldn't take u longer then 2 hours or so.
I don't think this is the right attitude towards forum users, who are here to try to help u. Not to help you, because u demand it.
Well, we can even show u how to do the code, but if u don't know what viewControllers are, or how to link stuff in IB. Then that's where it stops, read through the basics, can't really say more. Or quit ur class, and do something else.

(Sorry Dejo if this is offensive, but this made me crazy)

No worries, jnoxx. I don't find your comments offensive at all. alexpja on the other hand...