viral
viral

Reputation: 4208

Where to write request to WebService

I have created on UITableView, in which, tapping on any of the cell (-didSelectRowAtIndexPath) calls WebService associated with that cell.

Problem is to handle the JSon response, the Request returns. From where should I handle that response ?

As the view gets changed, as I tap on to the cell of the table (-didSelectRowAtIndexPath); I must pass all the response information to the next view.

Question is : Whether I should call the service after tapping the cell and before the next view getting loaded. Or Stick to this way (Which is making my code unmanageable.)

Which event is the most appropriate to handle this, (-didSelectRowAtIndexPath) or (-viewDidLoad) of the next view ?

Any suggestions?
Thanks.

Upvotes: 1

Views: 138

Answers (1)

Ilanchezhian
Ilanchezhian

Reputation: 17478

Once a row has been selected, allocate the NextViewController. Inform the NextViewController that the row has been selected by writing a setter method in NextViewController. In that setter method, start your request. Then push to the NextViewController.

You can handle the webrequest in NextViewController as currently that is being shown, you can reload the view depend on the response.

Edit

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    NextViewController *detailViewController = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
    id obj = [_list objectAtIndex:indexPath.row];
    //[detailViewController startWebRequest];
    [detailViewController startWebRequestWithObject:obj];
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
}

If you need to pass any object, pass it to the method. In the method, start the webrequest. And handle the response in the NextViewController.

Upvotes: 1

Related Questions