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

时间:2011-09-15 09:42:29

标签: iphone objective-c ios uitableview uinavigationcontroller

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

4 个答案:

答案 0 :(得分:1)

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


} 

答案 1 :(得分: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 :(得分:0)

使用方法处理tableview touch

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

您可以查看indexPath哪一行录音。

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

答案 3 :(得分:0)

使用tableview委托方法

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

SingleProductViewController是您要导航的新视图

一切顺利

相关问题