How do i know in the detail view what cell in tableview was selected?
how can i know what tableview cell was selected?(being in the detail view) The problem is that. I have an table view controller. Here are parsed from the internet entries to the table. So it's a dynamic tabe view that loads from internet. I will not know how many entries will be in the table so i will not know what details view to call when i click a row. So i have maked one view. This view contains an calendar. On this calendar(wich is the detail iew) i will parse data from internet depending on the selected row. For exemple: i have table: entry 1, entry 2,entry 3,entry 4 When i click entry 2 i need to call a php with the argument entry 2. The php will know what entry on the table i have selected and will generate me the correct xml that i will parse.
Here is my tableview didSelectRow function:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic -- create and push a new view controller
if(bdvController == nil)
bdvController = [[BookDetailViewController alloc] initWithNibName:@开发者_运维技巧"BookDetailView" bundle:[NSBundle mainBundle]];
Villa *aVilla = [appDelegate.villas objectAtIndex:indexPath.row];
[self.navigationController pushViewController:bdvController animated:YES]
And here is my self view function on detailviewcontroller:
-(void)loadView {
[super loadView];
self.title=@"Month"
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"ListView" style:UIBarButtonItemStyleDone target:self action:@selector(add:)];
self.navigationItem.rightBarButtonItem = addButtonItem;
calendarView = [[[KLCalendarView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 373.0f) delegate:self] autorelease];
appDelegate1 = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];
myTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 260, 320, 160)style:UITableViewStylePlain];
myTableView.dataSource=self;
myTableView.delegate=self;
UIView *myHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, myTableView.frame.size.width,2)];
myHeaderView.backgroundColor=[UIColor grayColor];
[myTableView setTableHeaderView:myHeaderView];
[self.view addSubview:myTableView];
[self.view addSubview:calendarView];
[self.view bringSubviewToFront:myTableView];
}
I think that here in self load i need to make the if procedure.. If indexPath.row=x parse fisier.php?variabila=title_of_rowx but the question is how i know the indexPath variable?
You can set a property on BookDetailViewController:
BookDetailViewController.h:
@interface BookDetailViewController : UITableViewController {
NSIndexPath *selectedIndexPath;
}
@property (nonatomic, retain) NSIndexPath *selectedIndexPath;
@end
BookDetailViewController.m
@implementation BookDetailViewController
@synthesize selectedIndexPath;
- (void)dealloc {
[selectedIndexPath release];
}
// ...
@end
tableView:didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic -- create and push a new view controller
if(bdvController == nil) {
bdvController = [[BookDetailViewController alloc] initWithNibName:@"BookDetailView" bundle:[NSBundle mainBundle]];
}
bdvController.selectedIndexPath = indexPath
Villa *aVilla = [appDelegate.villas objectAtIndex:indexPath.row];
[self.navigationController pushViewController:bdvController animated:YES]
}
Depending on what you're doing in your application it may make more sense to make the property a Villa object rather than an NSIndexPath.
精彩评论