![](/img/trans.png)
[英]How do I get the Detail View Controller to show text relevant to the “cell” selected on the TableView?
[英]How do i know in the detail view what cell in tableview was selected?
我怎么能知道選擇了哪個tableview單元格?(位於詳細視圖中)問題是這樣的。 我有一個表視圖控制器。 這里是從Internet條目到表的解析。 因此,這是一個從Internet加載的動態Tabe視圖。 我將不知道表格中將有多少個條目,因此當我單擊一行時,我將不知道要調用的詳細信息視圖。 所以我提出了一種看法。 此視圖包含一個日歷。 在此日歷上(這是詳細信息),我將根據所選行從Internet解析數據。 例如:我有表:條目1,條目2,條目3,條目4當我單擊條目2時,我需要使用參數條目2調用php。php將知道我選擇的表上的條目並將生成我將解析正確的xml。
這是我的tableview didSelectRow函數:
- (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]
這是我在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];
}
我認為在這里,我需要進行if過程..如果indexPath.row = x解析fisier.php?variabila = title_of_rowx,但問題是我如何知道indexPath變量?
您可以在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]
}
根據您在應用程序中執行的操作,將屬性設置為Villa對象而不是NSIndexPath可能更有意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.