HTML 文字列の配列があり、ユーザーがスワイプするたびに次の文字列を UIWebView に表示しようとしています。私の出力に基づいて、問題は、最初の HTML 文字列を viewWillAppear にロードすると、配列がすべて存在し、最初の HTML 文字列が webview に表示されるようですが、スワイプを swipedRight または swipedLeft に登録すると、確認したときに配列が突然空になります。クラスのプロパティとして配列を持っているので、なぜこれが起こっているのかわかりません。その何か愚かなように感じる..
私は質問(およびObjective-C)が初めてなので、他に必要なものがあれば教えてください..
ヘッダーに…
@property (nonatomic, weak)NSArray * slideDesctiptions;
@property (weak, nonatomic) IBOutlet UIWebView *webView;
そして、これが私の実装のコードです..
@interface TestViewController () <ArticleTableViewControllerDelegate>
@property (nonatomic, strong) IBOutlet TestView* testView;
@property (nonatomic, strong) NSString* description;
@property int marker;
@end
@implementation TestViewController
@synthesize slideDescriptions = _slideDescriptions;
@synthesize description = _description;
@synthesize marker = _marker;
@synthesize testView = _testView;
@synthesize webView = _webView;
-(void)setTestView:(TestView *)testView {
_testView = testView;
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipedRight:)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self.testView addGestureRecognizer:swipeRight];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipedLeft:)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.testView addGestureRecognizer:swipeLeft];
// [self.testView addSubview:self.webView];
}
-(void)viewWillAppear:(BOOL)animated{
self.marker =0;
self.description = [self.slideDescriptions objectAtIndex:0];
NSLog(@"description %@",[self.description description]);
NSLog([[NSString stringWithFormat:@"count %d", [self.slideDescriptions count]]description]);
self.webView.scalesPageToFit = YES;
[self.testView addSubview:self.webView];
[self.webView loadHTMLString:self.description baseURL:nil];
}
-(void)swipedRight :(UISwipeGestureRecognizer *) gesture{
NSLog([[NSString stringWithFormat:@"count %d", [self.slideDesctiptions count]]description]);
if ((gesture.state == UIGestureRecognizerStateChanged)
|| (gesture.state == UIGestureRecognizerStateEnded)){
NSLog(@"swiped right");
self.marker ++;
NSLog([[NSString stringWithFormat:@"count %d", [self.slideDescriptions count]]description]);
NSLog(@"description to be shown %@",[self.description description]);
self.description = [self.slideDesctiptions objectAtIndex:self.marker];
[self.webView loadHTMLString:self.description baseURL:nil];
}
}
-(void)swipedLeft :(UISwipeGestureRecognizer *) gesture{
if ((gesture.state == UIGestureRecognizerStateChanged)
|| (gesture.state == UIGestureRecognizerStateEnded)){
NSLog(@"swipted left");
self.marker --;
self.description = [self.slideDesctiptions objectAtIndex:self.marker];
[self.webView loadHTMLString:self.description baseURL:nil];
}
}
@end
出力:
2013-06-24 10:59:44.300 PlairTest[1667:c07] description <p>We are now roughly one month from the 2013 MLB All-Star Game, with two-and-a-half months of the 2013 season now in the books.</p><p>As the weeks pass, there is more and more separation between the contenders and the non-contenders, but this past week showed that things are still far from decided. </p><p>The San Diego Padres, Kansas City Royals and Toronto Blue Jays checked in at 18-20 in last week's power rankings and went a combined 16-3 last week. Meanwhile, the Rangers and Yankees stood at No. 5 and No. 6, and they went a combined 2-11. </p><p>Those were not the only surprises this past week, and needless to say, there was plenty of shakeup in the rankings as a result.</p><p>So here is a look at this week's updated <a href="http://bleacherreport.com/articles/1630131-updated-mlb-power-rankings">MLB power rankings</a>, with the focus this week being on who each team's five most valuable players are right now, according to WAR. Be sure to check back here each Monday morning for an updated look at where your favorite team stands.</p><p> </p><p><em>*Note: All WAR statistics courtesy of <a href="http://www.fangraphs.com/">FanGraphs.com</a> and current through June 15. All other statistics current through June 16.</em></p>
2013-06-24 10:59:44.301 PlairTest[1667:c07] count 31
2013-06-24 10:52:38.563 PlairTest[1646:c07] count 0
2013-06-24 10:52:38.564 PlairTest[1646:c07] swiped right
2013-06-24 10:52:38.564 PlairTest[1646:c07] count 0
2013-06-24 10:52:38.564 PlairTest[1646:c07] slide to be shown (null)
2013-06-24 10:52:38.564 PlairTest[1646:c07] description <p>We are now roughly one month from the 2013 MLB All-Star Game, with two-and-a-half months of the 2013 season now in the books.</p><p>As the weeks pass, there is more and more separation between the contenders and the non-contenders, but this past week showed that things are still far from decided. </p><p>The San Diego Padres, Kansas City Royals and Toronto Blue Jays checked in at 18-20 in last week's power rankings and went a combined 16-3 last week. Meanwhile, the Rangers and Yankees stood at No. 5 and No. 6, and they went a combined 2-11. </p><p>Those were not the only surprises this past week, and needless to say, there was plenty of shakeup in the rankings as a result.</p><p>So here is a look at this week's updated <a href="http://bleacherreport.com/articles/1630131-updated-mlb-power-rankings">MLB power rankings</a>, with the focus this week being on who each team's five most valuable players are right now, according to WAR. Be sure to check back here each Monday morning for an updated look at where your favorite team stands.</p><p> </p><p><em>*Note: All WAR statistics courtesy of <a href="http://www.fangraphs.com/">FanGraphs.com</a> and current through June 15. All other statistics current through June 16.</em></p>