【发布时间】:2015-04-14 11:40:23
【问题描述】:
我有一个UIButton 可以将我的UICollectionView 滚动到右侧。该按钮被添加到我的UICollectionView 的超级视图中,因此它漂浮在单元格的顶部。
但我只能让UIAction 发生一次。如何复制操作或刷新按钮以便我可以再次使用它。
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(910, 345 , 100, 100);
button.backgroundColor = [UIColor purpleColor];
[self.collectionView.superview addSubview:button];
[button addTarget:self action:@selector(changeContentOffset:) forControlEvents:UIControlEventTouchUpInside];
}
- (IBAction)changeContentOffset:(id)sender {
[self.collectionView setContentOffset:CGPointMake(910, -65) animated:YES];
}
【问题讨论】:
-
每次你点击它时都会调用按钮操作。无论如何,在将按钮作为子视图添加到 collectionView 之前添加按钮操作。你从 collectionview 中删除按钮的任何地方?
-
将所有按钮代码放在 cellForItemAtIndexPath 而不是 ViewDidLoad 中,并将按钮添加到 contentView 而不是 collectionView.superview..
标签: ios objective-c uibutton uicollectionview refresh