0

を作るのに助けが必要while statementです。アニメーションでさまざまな画像を取得しました。しかし、アニメーションの後に同じ画像を表示したくありません。

元。現在の動作: image1 が表示されます -> image3 が表示されます -> image3 が表示されます。

常に新しい画像が表示されるようにしたい。

- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];


int interval = 5+(arc4random() % 6);

int section = 0;
int row = (arc4random() % self.jsonDict.count);


NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
[NSTimer scheduledTimerWithTimeInterval:interval
                                 target:self
                               selector:@selector(updateCells:)
                               userInfo:indexPath
                                repeats:NO];

    NSLog(@"seconds: %d", interval);
    NSLog(@"row: %d", row);}



- (void)updateCells:(NSTimer *)timer {



NSIndexPath *indexPath = [timer userInfo];
NSObject *obj = [_jsonDict objectAtIndex:indexPath.row];
NSLog(@"array: %@", obj);

UIImage *img = [self randomImageWithObject:obj];

NSString *title = [obj valueForKey:@"title"];
NSLog(@"array: %@", title);

CollectionCell *cell = (CollectionCell *)[self.collectionView cellForItemAtIndexPath:indexPath];

[UIView transitionWithView:cell
                  duration:1.0f
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{
                   cell.collectionImageView.image = img;
                } completion:nil];



int interval = 5+(arc4random() % 6);
int section = 0;
int row = (arc4random() % [_jsonDict count]);

NSLog(@"speedeee: %d", interval);
NSLog(@"row: %d", row);

NSIndexPath *indexPath2 = [NSIndexPath indexPathForRow:row inSection:section];



//CollectionCell *newCell = (CollectionCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
[NSTimer scheduledTimerWithTimeInterval:interval
                                 target:self
                               selector:@selector(updateCells:)
                               userInfo:indexPath2
                                repeats:NO];}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [_jsonDict count];}-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{


CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ReuseID" forIndexPath:indexPath];

NSObject *obj = [_jsonDict objectAtIndex:indexPath.row];

//NSLog(@"object: %@", obj);

NSArray *images = [obj valueForKey:@"images"];
NSString *imageName = images[0];
//NSLog(@"name: %@", imageName);

cell.collectionImageView.image = [UIImage imageNamed:imageName];


[self cellTitleAndBackground:cell indexPath:indexPath];

return cell;}

- (UIImage *)randomImageWithObject:(NSObject *)obj{
// Random image for cells



NSArray *images = [obj valueForKey:@"images"];
NSInteger randomNumber = arc4random() % [images count];

return [UIImage imageNamed:[images objectAtIndex:randomNumber]];}
4

2 に答える 2

0

コレクションには、次を使用する必要があります。

indexPath.item

それ以外の

indexPath.row

詳細はこちら (TableView の行、CollectionView の項目):

https://developer.apple.com/library/ios/documentation/uikit/reference/NSIndexPath_UIKitAdditions/Reference/Reference.html

于 2013-09-12T11:14:57.793 に答える