我有一個工作樣本的UICollectionView,我可以移動一個單元格[通過indexPath],但我需要一個特定的單元格[indexpath.row?]所以我移動我需要的單元格,移動,但不正確的,所以 當我移動例如UICollectionView移動特定單元格
NSIndexPath *指數= [indexPaths objectAtIndex:0];
indexpath.row = 3上的單元格移動,如何通過indexpath行調用單元格?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor lightGrayColor];
CGRect frame = CGRectMake(10, 100, 300, 500);
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
self.collectionView=[[UICollectionView alloc] initWithFrame:frame collectionViewLayout:layout];
[self.collectionView setDataSource:self];
[self.collectionView setDelegate:self];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
[self.collectionView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:self.collectionView];
UIButton *animus = [UIButton buttonWithType:UIButtonTypeRoundedRect];
animus.frame = CGRectMake(100, 20, 90, 30);
[animus setTitle:@"Animus" forState:UIControlStateNormal];
[animus addTarget:self action:@selector(animusPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:animus];
}
- (void)animusPressed:(id)sender
{
NSIndexPath *index = [indexPaths objectAtIndex:0]; //en el index!
NSLog(@"moving tha cell :: %d", index.row);
__weak UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:index]; // Avoid retain cycles
CGRect frame = cell.frame;
frame.origin.y = 300;
cell.frame = frame;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
cell.backgroundColor=[UIColor greenColor];
UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, cell.bounds.size.width, 40)];
[cell.contentView addSubview:title];
NSString *titleLbl = [NSString stringWithFormat:@"i = %d", indexPath.row];
title.text = titleLbl;
return cell;
}
所以小區的動作,但不是我想要的,我需要一個像它是在cellForRow顯示了對移動特定的細胞,通過indexpath.row,
如何指定我想要移動的單元格?
請注意IM在指數= 0移向細胞,但indexpath.row = 2是一個移動
感謝