0
3ページで表ビュー内にスクロールビューをレンダリングする次のコードがあります。ページを5秒ごとに変更したいのですが、どうすればいいですか?iOSのタイマーでUIScrollViewをスワイプ
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier: sliderIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sliderIdentifier];
}
if (sliderItems != nil && sliderItems.count > 0) {
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, 200)];
scroll.scrollEnabled = YES;
for (int i = 0; i < sliderItems.count ; i++) {
CGFloat xOrigin = i * self.view.frame.size.width;
UIImageView *awesomeView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, 200)];
ItemResponse *test = [ItemResponse new];
test = sliderItems[i];
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//this will start the image loading in bg
dispatch_async(concurrentQueue, ^{
NSString *urlStr = test.listingImage;
NSURL *imageUrl = [NSURL URLWithString:urlStr];
NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
//this will set the image when loading is finished
dispatch_async(dispatch_get_main_queue(), ^{
awesomeView.image = [UIImage imageWithData:imageData];
[scroll addSubview:awesomeView];
UILabel *iconAdLabel = [[UILabel alloc]init];
iconAdLabel.frame = CGRectMake(0 + (i * self.view.frame.size.width),130,self.view.frame.size.width,70);
iconAdLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
NSString *titleStr = [NSString stringWithFormat:@" %@ ", test.listingTitle];
iconAdLabel.text = titleStr;
UIColor *color = [self getUIColorObjectFromHexString:@"#000000" alpha:0.6];
iconAdLabel.backgroundColor = color;
UIColor *textcolor = [self getUIColorObjectFromHexString:@"#ffffff" alpha:1.0];
iconAdLabel.textColor = textcolor;
iconAdLabel.textAlignment = NSTextAlignmentRight;
UIFont *font=[UIFont fontWithName:@"NotoKufiArabic" size:14.0f];
iconAdLabel.font = font;
iconAdLabel.numberOfLines = 2;
[scroll addSubview:iconAdLabel];
});
});
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * sliderItems.count , 200);
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//this will start the image loading in bg
dispatch_async(concurrentQueue, ^{
dispatch_async(dispatch_get_main_queue(), ^{
[self.view addSubview:scroll];
});
});
}
return cell;
NSTimerをセットアップして5秒ごとに関数を呼び出し、その関数のscrollViewのコンテンツオフセットを変更します。これにより、scrollViewがより広い範囲に収まるようになり、 'cellForRow'と新しい関数の両方で使うことができます。 – NSGangster