【问题标题】:How do i know in the detail view what cell in tableview was selected?我如何知道在详细视图中选择了 tableview 中的哪个单元格?
【发布时间】:2010-05-20 12:42:19
【问题描述】:

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

【问题讨论】:

    标签: iphone xcode uitableview didselectrowatindexpath


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-14
      • 2015-08-07
      • 2012-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多