i have a UITableview, in the tableview i'm grabbing a JSON feed. But sometimes it's displaying htmlcharacters like “ instead of “ does anyone know how i can convert this in xcode?
Can i set a encoding for my textlabel?
[[cell textLabel] setText:[item objectForKey:#"title" ]];
When I'm fetching strings from a web server and if they're destined for any User Interface, I usually de-louse (errr, de-percent-escape them) via this "NSString" method:
stringByReplacingPercentEscapesUsingEncoding (documentation linked for you).
This gets rid of the URL encoded pieces of strings.
Now, as to the HTML characters like "“", that requires an additional NSString category to do some work.
And other people have already written this category for you. Take a look at the various answers here and one of them should work well.
Related
I have an app that basically search youTube videos.
This all youTube search and the result videos are in one view controller.
Now, everything works fine and i do get the wanted videos (using JSON) displayed on my view using this API: "https://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=%#"
The problems are:
1. UISearchBar accepts only one word to search with. if i put on the search bar two or more words, the app crashes. (if i don't want that the two words will make my app crash,
then i need to write on the searchBar, i.e "new%20songs" instead of "new songs").
so the question for here is: do i need to detect every space on the seachBar.text and replace it with "%20"?
or there is something more appropriate for that..?
another thing: language- my UISearchBar accepts only english! if i put another language on it-CRASH!
Do anyone have an explanation? i tried to change some of the API rules, but unsuccessfully.
EDIT: i'm not leaving here code, because i don't think it's the problem. the code works fine.. i think it's more like API problem, but of course, i'll post some code if needed.
Thanks to all !!!
To obtain the correct URL string you need to use stringByAddingPercentEscapesUsingEncoding method. So all spaces and characters (other than English) will be replaced by special codes (eg space will be replaced %20, etc.). Example:
NSString *searchStr = #"string with space";
NSString *youtubeURLString = [NSString stringWithFormat:#"https://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=%#", searchStr];
NSString *URLString = [youtubeURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
I have an NStextView that loads a description from a JSON source. The NSTextView loads a different string every time the user clicks a button. These descriptions sometimes have a URL in them which is rendered as plain text and not as a clickable URL. It loads just fine, it's just that URL's aren't recognized. I've set up automatic link detection to no avail. I also tried AttributedString which didn't work, but that may be my incompetence (new to this.)
Here's the code:
if ([firstCommenter isEqualToString:playerID]) {
NSString *commentBody = [[allComments objectAtIndex:0] valueForKeyPath:#"body"];
[shotDescriptionTextView setString:commentBody];
}
Refer Automatic Link Detection in an NSTextView. Hope helpful
For even better solution without need of any category look here
TL;DR:
[shotDescriptionTextView setEditable:YES];
[shotDescriptionTextView checkTextInDocument:nil];
[shotDescriptionTextView setEditable:NO];
Is there a list of the codes UIWebView returns in - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error? For example "A server with the specified hostname could not be found." returns -1003. Does Apple, or anyone else, provide a list with all the codes UIWebView returns?
Not specifically UIWebView but there are header files that contain network error codes. CFNetworkErrors.h has the actual numbers and NSURLError.h has the Cocoa symbols. You should be able to find the versions of them that match your SDK by using Spotlight for those file names.
The list of UIWebView related error-codes with description are available in Foundation Constants Reference or CFNetWorkErrors enumeration.
I am starting objective C and i want to make a form with text inputs. I have many Text Fields on my view and i want to check if the values written are good (only numbers, only text).
How can i do that? I found some documentation but not a lot... If anyone has a good ressource to help me to make forms.
I also want to know how to get all values in an array.
Thank you for help and sorry if my questions look terrible and easy.
I know ruby, php, javascript :)
Given a textfield called textfield1, you can access its string content via textfield1.text. This will yield a NSString-object which you can then analyze. You may use NSRegularExpression for this, or loop through 1-char-substrings or whatever you like, read up on NSString for this. A Google Search will also quickly yield you examples on how to use NSRegularExpressions.
Seeing that you're working for iOS, you might want to consider using special controls for your specific needs. For example, rather than using a textfield to request a number, and complain when the user inputs a non-number, present him a slider instead of a textfield.
For your second question, given an array array1 with NSString objects in it, you can loop through them by fast enumeration:
for (NSString* string in array1)
{
// do something with each string in array1
}
I need to take an existing pdf file and programmatically fill in a list of form fields with text and then save the pdf without ever displaying it to the user.
For instance, if the pdf file contains fields named "LastName", and "FirstName" I would like to set the value of "FirstName" to "Louis" and then save the file.
I've been searching for a long time and can't find any guidance on even where to start since the iOS documentation (and most of the questions on here) seem geared towards displaying or creating pdf content instead of modifying it.
EDIT:
My main question is: Is it possible to open a pdf stream (I know how to do this) and copy each existing pdf dictionary item into a new pdf? I have not been able to find a way to write the dictionary items to a pdf.
I doubt that kind of functionality will ever be in the iOS frameworks. The reason most of the related info you can find "seem[s] geared towards displaying or creating pdf content instead of modifying it" is because that's what the vast majority of use cases will want or need for PDF functionality.
You'll need to find a 3rd party library that can open up PDFs, fill out the AcroForm fields, and then stamp out a PDF. I use iText on Java (there is also iTextSharp for C#) but I don't know of anything for Objective-C.
Once you find that library, you'll need to integrate it into your project. There are undoubtedly several related questions/answers here on SO for whatever version of the SDK you're using.
This would be easier to do with a HTML page. If you wish to use a HTML page instead of a .pdf form then thius is how you would go about doing it:
[field1 setText:#"Field 1 Text"];
[field2 setText:#"Field 2 Text"];
NSString *result;
result = [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"$('#field1').val('%#');", field1.text]];
result = [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"$('#pfield2').val('%#');", field2.text]];
result = [webView stringByEvaluatingJavaScriptFromString:#"$('#submitbutton').click();"];
You would need to create two UILabels or UITextFields and call them "field2" and "field2" in your .h file. You can then find the ID of the field you need to replace e.g. #field1 and then put it where I have put "#field1" and again for the second field where I have put "#field2". There also needs to be a UIWebView with the page already loaded. This code is to be used after the UIWebView page has been loaded. Maybe do the following:
-(void)webViewDidFinishLoad:(UIWebView *)webView {
// Insert above code here
}
You probably need a full understanding of Javascript if you want to do this for the whole form, but this should get you started.
Hope that helps you.