这是我之前的问题Add Swipe Gesture to display the next Item in the Detailed View
我之前已经问过这个问题,但不知道如何根据我的进度更新它。
我遵循了一些建议,但现在又被卡住了。
我现在想要向目标视图控制器添加一个滑动手势,这样我就可以转到下一篇文章而无需返回主页面。我添加了以下内容来设置手势以及加载数组中项目的功能。
所有这些数据都已通过segue传递给ViewController
-(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];
}
现在我陷入困境,并且不知道如何前进。请指教。
答案 0 :(得分:0)
您永远不会更改传递的索引:
[self loadArticleForIndex:_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;
}
}
因此什么都不会改变。您需要保留某种索引并在浏览文章时递增它。
[self loadArticleForIndex:currentIndex++];