添加滑动手势以在详细视图中显示下一个项目 - 修订 [英] Add Swipe Gesture to display the next Item in the Detailed View - Revised
问题描述
这是我之前的问题 添加滑动手势以在详细视图中显示下一个项目
我以前问过这个问题,但不知道如何根据我的进度更新它.
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.
所有这些数据都通过 segue 传递给了 ViewController
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.
推荐答案
你永远不会改变你传递的索引:
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++];
这篇关于添加滑动手势以在详细视图中显示下一个项目 - 修订的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!