如何从一个单元格导航到下一个视图?

发布于 2024-12-04 20:01:42 字数 85 浏览 0 评论 0原文

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

I want my app to have 5 rows and each row has a particular height. Each row has a title, subtitle and an image. Then i want to be able to navigate to the next page when i tap on either of the rows(for e.g say 3rd row). how do i do this?

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

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

发布评论

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

评论(4

陌上青苔 2024-12-11 20:01:42

问题第二部分的答案是 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
}

Answer to your 2nd part of the question is the initWithStyle:UITableViewCellStyleSubtitle…. this one allows you to have a title and subtitle. For the image, each cell has already built-in.

- (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
}
无法回应 2024-12-11 20:01:42
- (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


} 
- (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


} 
鱼忆七猫命九 2024-12-11 20:01:42

使用处理 tableview touch 的方法

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

您可以检查粘贴了哪一行的 indexPath

请参阅本教程 - 使用表在数据层次结构中导航浏览次数

Use method for handle tableview touch

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

You can check indexPath which row taped.

See this tutorial - Navigating a Data Hierarchy With Table Views

双手揣兜 2024-12-11 20:01:42

使用 tableview 委托方法

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

SingleProductViewController 是您想要导航的新视图

祝一切顺利

Use the tableview delegate method

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

SingleProductViewController is the new view you want to navigate

All the best

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