satishiOS25
satishiOS25

Reputation: 531

Pushing the ViewController in customize Tableview Cell

I'm using Using Customize table cell and have a button action in that cell and tapping on that should take me to another ViewController, I'm using this code inside the button action but its not working out:

 PhotoViewController *photo = [[PhotoViewController alloc]initWithNibName:@"PhotoViewController" bundle:nil];
  [self.navigationController pushViewController:photo animated:YES];

Upvotes: 3

Views: 380

Answers (2)

Hardik Kardani
Hardik Kardani

Reputation: 576

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *tableIdentifier = @"StaticTableViewCell";
   StaticTableViewCell *cell = (FriendTableViewCell *)[tableView dequeueReusableCellWithIdentifier:tableIdentifier];

if (cell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"StaticTableViewCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}
    cell.button.tag = indexPath.row;
    [cell.button addTarget:self action:@selector(PhotoAlb:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}
-(void)PhotoAlb:(id)sender
{
    PhotoViewController *photo = [[PhotoViewController alloc]initWithNibName:@"PhotoViewController" bundle:nil];
    [self.navigationController pushViewController:photo animated:YES];
}

Upvotes: 0

satishiOS25
satishiOS25

Reputation: 531

Got the solution :-) thanks Created the IBOutlet and in cellForRowAtIndexPath method declared:

 cell.photoAlbum.tag = indexPath.row; [cell.photoAlbum addTarget:self 
action:@selector(photoAblumClicked:) forControlEvents:UIControlEventTouchUpInside]; 

and in the photoAblumClicked called the above code it's working fine Thanks :-)

Upvotes: 1

Related Questions