Sanju
Sanju

Reputation: 129

How To Get UIPageviewcontroller Index Value After Select The Tableview Cell Using Objective C?

In my secnario I have maintaining within mainviewcontroller one page viewcontroller with 10 pages (viwcontrollers) and one tableviw with multiple rows. Now If I swipe the pageviewcontroller (top box) I can get page Index. Same time underthe table row If I select I need to get page view controller Index value.

enter image description here

Upvotes: 0

Views: 511

Answers (2)

Priyanta Singh
Priyanta Singh

Reputation: 77

Because not having the enough reputation to comment , i am putting my view in answer. @Sanju you are getting index of PageViewController . you only need to print that index when selecting TableViewCell.

just save that index value somewhere. i suggest to save in NSUserDefaults and you can use your index value anywhere in your project. go through this Link

Upvotes: 1

Shravan
Shravan

Reputation: 438

  1. First import the pageViewController.h file in ur tableViewController
  2. Create a @property in pageViewController to store the selected row data
  3. then u need to do the following in ur

didSelectRowAtIndexPath:

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

    [self performSegueWithIdentifier:@"pageView" sender:self];
}

Create a prepareforSegueMethod to send the details

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender       {
pageViewController *sendDetails = segue.destinationViewController;

  if ([[segue identifier] isEqualToString:@"viewDetail"])
  {
      NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
      NSInteger row = indexPath.row;
      sendDetails.selectedRow = row;
  }    
}

now u can use the selectedRow property to get the value

so whenever u click the cell u will be directed to the next page along with index number...

Upvotes: 0

Related Questions