A. Is it possible/appropriate to initialize NSXML parse for a selected row inside didSelectRowAtIndexPath in order to populate the detail view that the method pushes to? I want to parse the URL associated with the title of a selected item as a detailview...
B. If yes, then how can I make it happen? I have 'afeed.title' In the following critter:
NSXMLParser *urlParser = [[NSXMLParser alloc] initWithContentsOfURL:afeed.url];
A caution line exclaims at afeed.url: "Incompatible pointer types sending 'NSString *' to parameter of type 'NSURL *'"
afeed is create by this:
ArticleGroupLink *afeed = [array objectAtIndex:indexPath.row];
ArticleGroupLink is a class containing title (title was used in the cellForRowAtIndexpath method) & url (string & # property), which synthesizes them.
Let me know anything else that I need to share : )
As the compiler is trying to tell you is that it's expecting a NSURL object but instead you are giving it a NSString object.
So you can try to convert your NSString into a NSURL by doing something like this:
NSString *urlString = afeed.url;
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Then you can do:
NSXMLParser *urlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
Related
How to check the value of button accept or reject which is comes from database and in the reslt user click on it and accept it and the accept value is save in the database.
There is two button one for accept the request and other for reject the request. I show you the accept request button code,where I write the condition if the status of the request is pending or rejected so the user is able to click on it and in return button text is convert into accepted text.
Here is the condition of accept button. If I click on it so it check the value of pending and rejected and give the result of accept text in the button.
The button code is:
- (IBAction)btn_Accept:(UIButton *)sender
{
Request *comingReq = [objectHolderArray objectAtIndex:sender.tag];
if ([comingReq.status isEqualToString:#"Pending"] || [comingReq.status isEqualToString:#"Rejected" ])
{
objectHolderArray = [[NSMutableArray alloc]init];
NSString *ID = [prefs stringForKey:#"id"];
NSLog(#"%#" , ID);
NSString *urlString = [NSString stringWithFormat:#""];
NSURL *URL = [NSURL URLWithString:urlString];
NSData *jsonData = [NSData dataWithContentsOfURL:URL];
} else if ([comingReq.status isEqualToString:#"Pending" ]) || ([comingReq.status isEqualToString:#"Accepted" ]) {
NSURL *URL = [NSURL URLWithString:#""];
NSData *jsonData = [NSData dataWithContentsOfURL:URL];
}
When I passed a .text to hidden_status so there is no error but when I passed the .text to the btn_Accept so it gives an error.what type I used for btn_accept.
Dot notation lets you invoke the getter/setter of an object's property.
The code cell.hidden_status.text = #"string" says "fetch the hidden_status property of cell. Then set the text property of hidden_status to "string".
The compiler will complain if the type of "cell" does not have a property "hidden_status". Likewise it will complain if the type of the cell's hidden_status property does not have a text property.
UITextField and UITextView objects have text properties. UIButton objects do not have a text property, so you can't use code like
button.text = #"string"
If you want to set the title of a button there is a special method, -[setTitle:forSate:] that lets you set a button's title.
Is that what you're looking for?
Looking to simply convert the parse image url to a string so I can use SDWebImage for caching, etc.
After researching I found that I can convert from a url to string by calling absoluteString on the NSURL. I've also tried this:
NSURL *theUrl = [[obj objectForKey:#"image"] url];
NSString *finalUrl = [theUrl absoluteString];
[cell.carPhoto setImageWithURL:[NSURL URLWithString:finalUrl]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
but I am also crashing on this line with the same error
NSString *finalUrl = [theUrl absoluteString];
Any ideas? By the way obj is a PFObject
The error message is telling you that you have an instance of __NSCFString, and you're calling absoluteString on it. __NSCFString is a kind of NSString, so the situation is simply that you expect (for some reason) that you have an NSURL, but you actually have an NSString - so you don't need to call absoluteString.
It would be good to understand why you think you have an NSURL and whether you will ever have one in this piece of code. The inputs should really be consistent, but if not you can check the class and decide how to get the string version.
It looks like you're trying to convert a NSString to an NSURL with this line:
NSURL *theUrl = [[obj objectForKey:#"image"] url];
But that's not how you convert an NSString to an NSURL and so your NSString isn't being changed to an NSURL as you'd like. Instead, it seems as if it's remained an NSString, thus the error.
There's no need to convert the NSString to an NSURL if the only purpose of that NSURL is to be converted back to an NSString on the next line by accessing its absoluteString property; but if you do in fact need theURL to be an NSURL for reasons beyond the code you've posted (for example, if you need to access the NSURL variable later in your code), try this instead to properly convert your string into an url:
NSURL *theUrl = [NSURL URLWithString:[obj objectForKey:#"image"]];
Currently, I have within my iPhone app a URL with which contains a JSON object that I must parse.
I am able to fetch the JSON object, convert the object to an NSString, now the issue is parsing the object/NSString object.
I am currently using SBJSON.
How do I go about iterating through the key elements of the JSON object using SBJSON's framework?
{
"status":"SUCCESS",
"fields":[
{
"type":"instant",
"field":"GenerationPower",
"label":"now",
The JSON object is MUCH larger than just these keys and key elements but once this issue is resolved, I'm sure the rest of the JSON object will be easy since i'll have a reference.
Thank you Stackoverflow!
EDIT:
Here's some code to clarify my issue.
+ (NSString *) pullingInfo
{
NSURL *solarWebURL = [NSURL URLWithString:myurl];
if (solarWebURL)
{
NSLog(#"Calling: %#", solarWebURL);
NSData *jsonData = [NSData dataWithContentsOfURL:solarWebURL];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
return jsonString;
}
NSString* errorMessage = #"Error reading URL";
return errorMessage;
}
+ (NSDictionary *) jsonDictionaryObject
{
NSDictionary * jsonDictionary = [[NSDictionary alloc] init];
NSString * monroeString = [MonroeParser pullingInfo];
return jsonDictionary;
}
So as I said before, I have already loaded the JSON object into an NSString object "jsonString". Now I would like to start parsing the string.
I figure I may not even need to use JSON's framework for parsing, I can probably just parse the NSString using NSString conventions provided by Apple.
Any idea's? But maybe this isn't efficient....
Sine you are using SBJSON, why are you even converting the NSData to an NSString? You can use -objectWithData method for SBJSONParser to directly read the NSData into an NSDictionary.
http://sbjson.org/api/3.2/Classes/SBJsonParser.html#//api/name/objectWithData:
Let pullingInfo return an id. And in you calling function check if the id is of type NSDictionary or NSArray and parse accordingly.
I am attempting to retrieve a list of friends with specific fields using the iOS 6 Social Framework. I am using the URL:
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:#"fbUserID"];
NSString *urlString = [NSString stringWithFormat:#"https://graph.facebook.com/%#/friends?fields=id,name,picture", username];
NSURL *friendsList = [NSURL URLWithString:urlString];
But the framework seems to be appending the access key to it automagically, and is doing so with a '?' as if it were the first URL parameter. What's more, the API is complaining that it was expecting the end of the statement and not a ?, as is evident in this error:
error = {
code = 2500;
message = "Syntax error \"Expected end of string instead of \"?\".\" at character 15: id,name,picture?access_token=HHyDtnfrjnojngehrtjgnekngeXsI0ZBansnfjDHDhljoQKIfZB5i3JMUHlJIm5HHdwM4s5ixyu38es1vj9XXTcLSS6ZCOi13zQW87dw9YP3DgpllDz5KB6WnSeYGxS9RMfd3npZBwZAEUdmkJHoYlWvflfcQHVwIydLfExjOaNpGZBGhYvb3XlrZAXt7jmDai6FiMoZBRmdOUWfA5vubeNbvvn9y80cPaUPZBZCAZDZD";
type = OAuthException;
};
Is this normal behavior for the framework? Is the access token usually appended in this manner? If so, how should I form my urlString so that this is not a problem?
Instead of putting the "fields" param in the NSURL, try creating just a plain NSURL
NSString *urlString = [NSString stringWithFormat:#"https://graph.facebook.com/%#/friends", username];
NSURL *friendsList = [NSURL URLWithString:urlString];
And call requestForServiceType:requestMethod:URL:parameters, and pass in something like:
#{#"fields": #"id,name,picture"}
for the "parameters" field.
I am getting this error: [NSURL stringByAppendingFormat:]: unrecognized selector sent to instance 0x5869210 when it gets to the append. strcust is a plain number and strURI is correct until the append.
NSString *strUIR = [NSURL URLWithString:#"https://cid.hooru.mobi:36610/?";
strURI = [strURI stringByAppendingFormat:#&Cust=IPRR%#", strCust];
Any thoughts would be appreciated. I am just trying to append Name/value pairs from variables. Can't get the append to work.
There are several problems with this piece of code:
You're declaring an NSString but you are assigning an NSURL
You're missing a right square bracket ']'
You're missing a double quote on your second line
You're trying to call an NSString method on an NSURL object
You're misspelling strURI on your first line (it is strUIR)
Try this:
NSString *strURI = #"https://cid.hooru.mobi:36610/?";
strURI = [strURI stringByAppendingFormat:#"&Cust=IPRR%d", strCust];
//Note the %d (if strCust is an int. If it's an NSString use %#)
NSURL *myUrl = [NSURL UrlWithString:strURI];
[NSURL URLWithString:] returns pointer of type NSURL. Merely collecting the return value that is NSURL* type in NSString* type does not convert it to NSString* type. Therefore strUIR is NSURL* type, even though declared as NSString strUIR, and hence you cannot pass any message to strUIR that is supposed to be passed to NSString type.
NSURL doesn't respond to stringByAppendingFormat:
You specify strURI as an NSString so the compiler won't raise a warning, but you set it to an NSURL.
Either initialize the full string before creating the NSURL, or use URLByAppendingPathComponent:, I would recommend the first option.
NSString *path = #"https://cid.hooru.mobi:36610/?"
...
path = [path stringByAppendingFormat:#"&Cust=IPRR%#", strCust];
NSURL *url = [NSURL URLWithString:path]
For more information, see the docs: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html