问题
This is my previous question Add Swipe Gesture to display the next Item in the Detailed View
I have asked this question before but not sure how to update it with my progress.
I followed some suggestions but now I am stuck again.
I want to now add a swipe gesture to the destination view controller so that I can get to the next article without having to go back to the main page. I have added the following to set up the gesture as well as a function to load the items in the array.
All this data has been passed to the ViewController via segue
-(IBAction)swipeHandler:(UISwipeGestureRecognizer *)gesture{
{
    [self loadArticleForIndex:_articleListsports.count];
    NSLog(@"SWIPE");
    NSLog(@"Found %d character(s).", [_articleListsports count]);
}
- (void)loadArticleForIndex:(int)index
{
    //draw ur article or load your webview.
    if(index>0 && index <[_articleListsports count])
    {
        //self.targetURL  = selectedCell.targetURL;
        self.sdesc = self.sportsdescription.text;
        self.stitle = self.sportstitle.text;
        self.simage = self.sportsimage.image;
        self.scat = self.sportscategory.text;
        self.sdate = self.sportsdate.text;
    }
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UISwipeGestureRecognizer *recognizer;
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)];
    [recognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
    [[self view] addGestureRecognizer:recognizer];
    NSString *fileName = [NSString stringWithFormat:@"%@/sports.rss", [SPORTSUtil getDocumentRoot]];
    _articleListsports = [NSArray arrayWithContentsOfFile:fileName];     
}
Now I am stuck and have no clue on how to move forward. Please advise.
回答1:
You aren't ever changing the index you are passing with :
    [self loadArticleForIndex:_articleListsports.count];
So this routine will always show the same article:
    - (void)loadArticleForIndex:(int)index
   {
        //draw ur article or load your webview.
        if(index>0 && index <[_articleListsports count])
        {
            //self.targetURL  = selectedCell.targetURL;
            self.sdesc = self.sportsdescription.text;
            self.stitle = self.sportstitle.text;
            self.simage = self.sportsimage.image;
            self.scat = self.sportscategory.text;
            self.sdate = self.sportsdate.text;
        }
    }
and hence nothing will change. You need to keep some sort of index around and increment it as you swipe through the articles.
    [self loadArticleForIndex:currentIndex++];
    来源:https://stackoverflow.com/questions/18647620/add-swipe-gesture-to-display-the-next-item-in-the-detailed-view-revised