Search code examples
iphoneiosasihttprequest

How do I call a method from another method of the same NSObject?


I have two methods in my NSObject.

I would like to know how to set the text in one method from another, and then execute that method from the one where I set the text?

This is what I have done so far.. just getting abit lost trying to pass things between views and setting up tableviews.

- (IBAction) getManufacturers
{
    //set manufacture.php
    NSString *manufactureString = [[NSString alloc] initWithString:@"manufacture.php"];
    submissionString = manufactureString;
    self.grabURLInBackground; //<--- this is wrong, how do I call my other method?
}

//...


- (IBAction)grabURLInBackground:(id)sender
{
    NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8888/CodeTest/%@", settexthere];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDelegate:self];
    [request startAsynchronous];
}

//UPdated: So what I ended up doing is just adding a NSString paramater to grabURLInBackground method which is set from my other method like describeded below

[self grabURLInBackground:submissionString];

all is well.

Now I just need to figure out how to pass the data I have coming in to a new uitableview.. :) thanks for the help guys.


Solution

  • [self grabURLInBackground:nil];
    

    this should work if you declared the function in the prototype

    I think you want to set the string? In this case you need a new function

    prototype

    - (void) grabURLInBackgroundWithSubmission:(NSString*):submission;

    implementation

    - (void) grabURLInBackgroundWithSubmission:(NSString*):submission{
        NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8888/instaCodeTest/%@", submission];
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        [request setDelegate:self];
        [request startAsynchronous];
    }
    

    and call it with [self grabURLInBackgroundWithSubmission:submissionString];