【问题标题】:how to Navigate from one cell to next view?如何从一个单元格导航到下一个视图?
【发布时间】:2011-09-15 09:42:28
【问题描述】:

我希望我的应用有 5 行,每行都有特定的高度。每行都有一个标题、副标题和一个图像。然后,当我点击任一行(例如,第三行)时,我希望能够导航到下一页。我该怎么做?

【问题讨论】:

  • 我知道您可以使用自定义单元格添加图像和标签,但是我可以在表格视图中使用其他方法吗?
  • 我仍然不知道如何通过选择特定行来导航到下一页,我的意思是每行将导航到不同的页面,而不是提供不同的数据,所以怎么做我这样做?

标签: iphone objective-c ios uitableview uinavigationcontroller


【解决方案1】:

问题的第二部分的答案是 initWithStyle:UITableViewCellStyleSubtitle…。这个允许你有一个标题和副标题。对于图像,每个单元格都已内置。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    NSString *title = (@"your title");
    NSString *subTitle = (@"your subtitle");
    cell.textLabel.text = title;   //title
    cell.detailTextLabel.text = subTitle;   //subtitle
    NSString *filePath = //file path to your image
    UIImage *image = [UIImage imageWithContentsOfFile:filePath];
    cell.imageView.image = [myThumbnailClass image];  //image
}

【讨论】:

    【解决方案2】:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if(indexPath.row==0)
    {
     singleProductViewController=[[SingleProductViewController alloc]initWithNibName:@"SingleProductViewController" bundle:nil];
        [self.navigationController pushViewController:singleProductViewController animated:YES];
    [singleProductViewController release];
    }
    else if(indexPath.row==1)
    {
    //Sec view Navigation
    }
    //Like wise u go on
    
    
    } 
    

    【讨论】:

      【解决方案3】:

      处理tableview touch的使用方法

      - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
      }
      

      您可以查看indexPath 记录了哪一行。

      请参阅本教程 - Navigating a Data Hierarchy With Table Views

      【讨论】:

        【解决方案4】:

        使用tableview委托方法

            - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
            {    
                singleProductViewController=[[SingleProductViewController alloc]initWithNibName: @"SingleProductViewController" bundle:nil];
                [self.navigationController pushViewController:singleProductViewController animated:YES];
                [singleProductViewController release];       
            }   
        

        SingleProductViewController 是您要导航的新视图

        一切顺利

        【讨论】:

        • 谢谢,这真的很有帮助,但这仍然不能回答我的整个问题:p,如果你也可以帮助我解决其他部分,我们将不胜感激。
        • 我的意思是“其他部分”,如何在不使用自定义单元格的情况下在单元格中插入图像和标签或其他任何内容?这可能吗?
        • tableview 单元格默认具有标题、描述和图像属性。如果您想要更多标签是您想要自定义单元格的单元格。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-09
        • 1970-01-01
        • 2016-04-24
        • 2020-05-21
        相关资源
        最近更新 更多