Reputation: 1492
I am parsing XML and I select from the UITablevView but I have an issue that how I am going to change the link on each selection?
For example;
www.example.com/test12.php?d=0
www.example.com/test12.php?d=1&il=istanbul
www.example.com/test12.php?d=2&il=istanbul&ilce=kadikoy
How can I change the d= and il= and ilce= value on each select on the UITableView?
I have write this but couldn't go further.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = selectedCell.textLabel.text;
NSString *linkID = @"http://example/test12.php?d=@%&il=@%";
NSLog(@"%@ Selected", cellText);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
containerObject = [objectCollection objectAtIndex:indexPath.row];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Set up the cell...
cell.textLabel.text = containerObject.city;
return cell;
}
Thanks from now.
Upvotes: 0
Views: 97
Reputation: 2200
Basically you fetch the model from your row and insert the values via stringWithFormat:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
YourModel* containerObject = [objectCollection objectAtIndex:indexPath.row];
NSString *linkID = [NSString stringWithFormat:@"http://example/test12.php?d=%@&il=%@", containerObject.var1, containerObject.var2];
}
Upvotes: 1
Reputation: 119031
I'd do this with 3 different table view controllers and a navigation controller. Doing it this way keeps each controller simple and allows for a nice animation between drill levels so the user has a sense of what has changed.
Your data structure should be an array which contains dictionaries for each city. Each city dictionary contains an array of province dictionaries. Each province dictionary contains an array of places. (Technically these could be separate data structures and each holds a reference to the data that's required instead but let's keep it simple just now).
Each table view controller should take an array as its source of data. It should also take some other parameter, which could be the generated link so far.
The city view controller displays the list of city names (as you have it currently). When a row is selected, it gets the appropriate dictionary for the city, gets the array of provinces, creates a province view controller and passes it the provinces list. It also adds the city component to the link and passes that to the province view controller.
When a province is selected, the same process as above is followed.
When a place is selected, the final link component can be added and the link is now complete and can be used.
Upvotes: 0