开发者

how to Navigate from one cell to next view?

开发者 https://www.devze.com 2023-04-05 14:09 出处:网络
I want my app to have 5 r开发者_如何学JAVAows 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 eithe

I want my app to have 5 r开发者_如何学JAVAows 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?


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
}


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


} 


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号