我如何知道在详细视图中选择了表格视图中的哪个单元格?

发布于 2024-09-01 22:51:51 字数 1976 浏览 11 评论 0原文

我如何知道选择了哪个表格视图单元格?(在详细视图中) 问题是这样的。 我有一个表视图控制器。这里是从网上的条目解析到的表。 所以这是一个从互联网加载的动态标签视图。我不知道表中有多少条目,因此当我单击一行时,我不知道要调用哪些详细信息视图。 所以我提出了一种观点。该视图包含一个日历。在此日历上(这是详细信息),我将根据所选行解析来自互联网的数据。 例如:我有表:条目 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变量?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音盲 2024-09-08 22:51:52

您可以在 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 可能更有意义。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文