Add Swipe Gesture to display the next Item in the Detailed View - Revised

人走茶凉 提交于 2019-12-13 03:59:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!