I am trying to get a customized URL in a webview for the user but it is not working out so far. It crashes even though it returns no errors (the red code is the line that is crashing it). Anyone know a solution to use an NSString as NSURL.
I am trying to get a customized URL in a webview for the user but it is not working out so far. It crashes even though it returns no errors (the red code is the line that is crashing it). Anyone know a solution to use an NSString as NSURL.
I think I know at least one of your problems. I gather that yopmailLink is an instance variable of the class you are working on? (A view controller perhaps)
you are creating an autoreleased object. This object is temporary, and unless you send it a retain message, it will get released the next time your code returns to the main event loop.
The basic rule is this: System methods that begin with init, new, or copy return objects with a retain count of 1. Those objects are not temporary. You own them, and are responsible for sending them a release message when you are done with them.
For all other methods that return an object, unless the documentation specifically says that the object is returned with a retain count of 1, the object is autoreleased. That means it was sent an autorelease message. THAT means that the object no longer has an owner, and will be release soon.
You should probably change your yopmailLink variable to a retained property of your class, and then assign values to it using property syntax, like this:
When you change the value of a retained property using property syntax (like "object.property = value" or "[object setProperty: value]", the object runs a special bit of code called the "setter", that causes any old value of the property to be released, and the new value to be sent a retain message.
Once you are done with yopmailLink, you should say
Code:
self.yopmailLink =nil;
That will cause the old value of the property to be released.
You should read slick's tutorials on Cocoa memory management and properties.
For those of you trying to learn iOS programming, stop and learn about Cocoa memory management and how to use properties before you do ANYTHING else. Read and study this topic until it is second nature. If you follow a few simple rules, your code will work well. IF you mess up, even once, your program will either leak memory and eventually run out of memory and be terminated by the system, or you will have objects get released when you are still using them, and the next time you reference the object, your app will crash.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
It displays the email and goes to the page but for some reason it adds %0d between the name and the number. This is from the NSUTF8StringEncoding line but I cannot get it to work without that. Is there a fix?
It displays the email and goes to the page but for some reason it adds %0d between the name and the number. This is from the NSUTF8StringEncoding line but I cannot get it to work without that. Is there a fix?
Which line of code inserts a "%0d" between the name and number? The randomMailLabel.text = assignment? The self.yopmailLink assignment?
One thing I noticed: You are escaping the entire URL, and that is almost certainly wrong and going to cause you problems. That will escape the "://" in your URL (I think) which is bad. You want to escape your mail body before adding it to the URL. I changed the code above to show you what I mean, and put the changes in bold.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
I believe that the encoding is the thing that puts the number there. It displays normally otherwise. But if I have no encoding, it won't show up in the webview.
So the bolded line is 100% the line that adds the %0d. If the original was hi12, it would look like hi%0d12 after going through the encoding. Is there a fix for this so I can actually load the webpage? The webpage does not load without the encoding.
I changed the encoding to only encode the NSString CityToDisplay and I also got rid of the whole mailfull but it still gives @%D