First...if no one can answer this question it's ok...
because I don't know how to ask this question in the correctly description
my program is get the plist data from URL and show it on the iphone tableview
My colleagues give me two URL to get the plist data
So I have two tableviews(tableview1,tableview2)
two URLs(URL1,URL2)
My tableview1 via URL1 get a plist1 ,and tableview1 has 3 contents in first 3 rows
ex.(row0 id1),(row1 id2),(row2 id3)
When I select row0 ,it will jump to tableview2 and with a title id1 on the navgation bar
so far is I can do...
but at tableview2 ,it need a URL like: www.URL2.php?id=1 =>that means...
I have to add my tableview title after URL2
to get the right plist related the id 1
my question is .......URL2 is static,how to make it like dynamic to get the right URL address ???
well.....first time I thought my colleagues will give me a data like array of array
But it's not...I never try use URL like dynamic...
This is code in the tableview1 to let me get the plist from URL
NSURLRequest *theRequest=[NSURLRequest requestWithURL:appDelegate.URL1//I declare the URL at appDelegate.m for some reasons...
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSData *returnData = [NSURLConnection sendSynchronousRequest:theRequest
returningResponse:nil error:nil];
NSString *listFile = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
self.array = [listFile propertyList];//I parse the data from array to tablecview
and this is how I parse the title from Tableview1 to Tableview2
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
TableView2 *tb2 = [[TableView2 alloc]init];
tb2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
tb2.title = [[[array objectAtIndex:indexPath.row] valueForKey:#"name"]description];
[self.navigationController pushViewController:tb2 animated:YES]; }
Any ideas ?
well ...if someone can answer this or give me a direction I will very appreciate
Great Thanks for All Reply and Answers !!!
Oh...one more thing,I can use ASIHTTPRequest to post a data
but I don't know how to get data after post ...?(is this help ?)
Assuming you have a string that you want to append to appDelegate.URL1 declared as:
NSString *stringToAppend = #"whatever";
Then you can produce a string containing the new URL:
NSString *newURLAsString = [NSString stringWithFormat:#"%#%#",[appDelegate.URL1 absoluteString],stringToAppend];
And an NSURL from this string:
NSURL *newURL = [NSURL URLWithString:newURLAsString];
And the NSURLRequest from that:
NSURLRequest *theRequest=[NSURLRequest requestWithURL:newURL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
I'm not exactly sure what you are trying to say.
You want to load tableView1 from www.foo.com then when the user clicks a row it directs to another URL such as www.foo.com/row0.
The easiest way to acomplish that would be to create a property that you set in your selectedRow method
Something along the lines of.
Declare the property in your header
#Property (readwrite,copy) NSString* strURL;
To append the String to api
when you want to pass some string to your Api as a parameter
For example I store the lat and long of user and then pass that string to API's url
NSURL *address1=[NSURL URLWithString:[NSString stringWithFormat:#"http://maps.googleapis.com/maps/api/geocode/json?address=%#&sensor=false",location]];
NSLog(#"your lat and long is::%#",[NSString stringWithFormat:#"http://api.wunderground.com/api/90caafb557ba6bf7/geolookup/conditions/forecast/q/%#.json",location]);
Here Location is a NSString which store the latitude and longitude and i pass that data to API to fetch City,Country and tempetature etc..
with the help of %# we can pass the stored value to api
Related
I'm using JSON web service to collect data and display in my UITableView cell. My problem is when I try to call my web service, if the data has characters like & it gives me &.
When I try to store this JSON data in NSDictionary and after that display in UITableView cell it appear as it is.
Eg. if data is Chris & Priscilla originally it retrieves as Chris & Priscilla and same shows in my cell. I want to display it as Chris & Priscilla and not Chris & Priscilla.
It displays properly in browser.
I can't find what I missed.
NSError *error = nil;
NSString *strUrl = #"MY-WEBSERVICE-URL";
NSURL *url = [[NSURL alloc] initWithString:strUrl];
NSString *returnText = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
txt.text = returnText;
Usually HTML unescaping is done adding a category to NSString. There are many examples, i.e. here: http://google-toolbox-for-mac.googlecode.com/svn/trunk/Foundation/GTMNSString+HTML.h.
Particularly, have a look at
(NSString *)gtm_stringByUnescapingFromHTML;
I'm having trouble getting the user's profile pic with the new Facebook SDK. All the answers on here use methods from the old SDK that no longer work.
I've tried using the FBProfilePictureView recommended in Facebook's tutorial, but this picture doesn't get cached and I don't think it can be converted into a UIImage.
Can anyone please provide some help? Thanks!
OK, I finally got this using the following:
imageData = [[NSMutableData alloc] init]; // the image will be loaded in here
NSString *urlString = [NSString stringWithFormat:#"http://graph.facebook.com/%#/picture?type=large", user.id];
NSMutableURLRequest *urlRequest =
[NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:2];
// Run request asynchronously
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest
delegate:self];
if (!urlConnection)
NSLog(#"Failed to download picture");
Then I used -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data and -(void)connectionDidFinishLoading:(NSURLConnection *)connection to put the image together.
Best solution i've found:
I've used UIImage from AFNetworking https://github.com/AFNetworking/AFNetworking. It handles redirect and caching so you can fetch profile picture for every user id you have.
NSString *imageUrl = [NSString stringWithFormat:#"http://graph.facebook.com/%#/picture", ((NSDictionary<FBGraphUser> *) [self.friends objectAtIndex: indexPath.row]).id];
[friendCell.imageView setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:#"profile.jpg"]];
Use https://github.com/rs/SDWebImage to cache the image. The URL to request the image should be
NSString *string = [NSString stringWithFormat:#"https://graph.facebook.com/%#?fields=picture", userid];
Use the link:
https://graph.facebook.com/me?fields=picture
to get the current user's profile picture.
Facebook provides the Graph API explorer tool which can come in handy when you want to try queries or to check the returned output.
Here's a link to the User API Reference.
If your problem is related to "self.userPofilePicture.profileID = user.id;".
Then self.userProfilePicture return UIView so just take View and display in it.
Don't forgot add class FBProfilePictureView in Identity Inspector as well as [FBProfilePictureView class] to AppDelegate implementation file.
I hope this will helpful.
In my app i am retrieve data from web services and show in uitableview it is fine but problem is that in mu tableview suppose 10 row (that is city name and latitude longitude of all city that are in my table) after the retrieve city name i m trying to get Distance between user location and city so 10 times i need to call google mapAPI, in that process my app is crash.
i am using NSURLRequest
i had also used ASIHttpRequest - networkQueue but not get success.
so how many other ways to do this?
please suggest me any other types of request to fix it.
thanx for any suggestion.
here is my code
for (NSUInteger i=0; i<[latlongarray count]; i++)
{
NSString *urlString=[NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/distancematrix/json?origins=%#&destinations=%#&avoid=tolls&sensor=true",str,[latlongarray objectAtIndex:i]];
NSLog(#"%#",urlString);
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *myrequest=[[NSURLRequest alloc] initWithURL:url];
CustomConnection *distanceconnection=[[CustomConnection alloc] initWithRequest:myrequest delegate:self startImmediately:YES tag:[NSNumber numberWithInt:i]];
[distanceconnection start];
[distanceconnection release];
[myrequest release];
}
str is user location, and latlongarray is array for city's location.
You can go NSURLRequest operation with either synchronous or asynchronous way. According to me, dealing with NSURLRequest asynchronously is more advisable when response being is depended for further executions.
hello
I'm trying to write an rss feed viewer for my iPhone. In my DetailView I have a UIWebView where I want to display specific link retrieved with the rss item.:
NSString* url = [data objectForKey:#"link"];
NSString *encodedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ];
NSLog(#"Selected link:%#",url);
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:encodedUrl]];
[itemWebpage loadRequest:request];
[request release];
now,if the retrieved link is something like
www.shazaam.com
it works. But as soon as the link is something like:
http://www.shazam.com/music/web/track?id=41970148"
it doesn't. I suppose it's because of the parameter...but how can I fix the problem????
thanks a lot!
elos
stringByAddingPercentEscapesUsingEncoding: is for when you want to put a string into a query variable. You don't need to do it for entire URLs. The question mark is being encoded when it shouldn't be, so you are getting a 404. Don't encode the URL and you should be fine.
How do I read data from an USL link, and display it on my textview? The URL link content contains only normal text
I am using:
NSString *userAgreementStringURL = [NSString stringWithFormat:#"%#/requestConfigurationData.php?ownerID=%#&view=userAgreement", serverURL, ownerID];
NSURL *userAgreementURL = [NSURL URLWithString:userAgreementStringURL];
NSURLRequest *userAgreementRequest = [NSURLRequest requestWithURL:userAgreementURL];
userAgreementData = [[NSMutableData alloc] init];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
userAgreementConnection = [[NSURLConnection connectionWithRequest:userAgreementRequest delegate:self] retain];
[userAgreementTextView setText:[NSString stringWithContentsOfURL:#"http://medicinephone.com/dev2/visit/requestConfigurationData.php?ownerID=13&view=userAgreement" encoding:NSUTF8StringEncoding error:NULL]];
Show us your code. If you are trying what I think you are trying passing an array to text view's setText method won't work. You need to get the string from the array prior to that. If you array contains one word per array element you might want to try using componentsJoinedByString.
[myTextView setText:[NSString stringWithContentsOfURL:[NSURL URLWithString:#"http://apple.com" encoding:NSUTF8StringEncoding error:NULL]]];
one line of code, thank you apple.
Edit: forgot to make a NSURL from the string.