I am trying to load different sets of data into a single uitableview dependent on which cell was selected in the tableView:didSelectRowAtIndexPath: method of the previous view.
What i would like to do is set a value inside the newly pushed view that can change the requests that I do to a php script of my choosing.
For instance if I could pass my newly pushed view a number I would have an if statement or maybe a switch, that switch statemen开发者_JAVA百科t would then make use of my ASIFormDataRequest wrapper I am usnig telling my request nsobject to execute the php script I have related to this cell selection, then pass the data-back.
I hope this makes sense, if you have any experience with what I am trying to achive and can see a better way of doing it I would love to hear it.
You could create a property in the detail view controller that would be set from the didSelectRowAtIndexPath: method. This assumes you have your data stored in an NSArray as a array of numbers. Your implementation will likely vary from this, but the idea is the same.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detailViewController = [[DetailViewController alloc] init]];
detailViewController.number = [self.mydata objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
If you wanted to, you could also create a custom init method to pass this information. In your init method, you would set the property from the parameter passed into it.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNumber:[self.mydata objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
精彩评论