Ios 是否在操作时向UITableViewCell添加详细信息披露?
我有一个UITableView,其中填充了包含集合视图的单元格。我需要按下导航栏中的一个按钮,然后在我的所有单元格中添加一个详细信息披露按钮。这将使我能够点击它并将我推到一个新的视图控制器Ios 是否在操作时向UITableViewCell添加详细信息披露?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个UITableView,其中填充了包含集合视图的单元格。我需要按下导航栏中的一个按钮,然后在我的所有单元格中添加一个详细信息披露按钮。这将使我能够点击它并将我推到一个新的视图控制器 是否有一种方法可以将此操作动画化到所有“我的表格视图”单元格中,以便用户可以在点击按钮时显示或隐藏该功能?假设您希望在每个UICollectionViewCell实例上显示/隐藏自定义披露指示器: 在collectionView:cellForItemAtIndexPath:方法中,将单元格配置为基于某个状态
是否有一种方法可以将此操作动画化到所有“我的表格视图”单元格中,以便用户可以在点击按钮时显示或隐藏该功能?假设您希望在每个
UICollectionViewCell
实例上显示/隐藏自定义披露指示器:
在collectionView:cellForItemAtIndexPath:
方法中,将单元格配置为基于某个状态变量显示或隐藏披露指示符,以便作为滚动结果配置的新单元格具有正确的状态:
MyCollectionViewCell *cell = [self.collectionView dequeueReusableCellWithIdentifier:@"MyCellIdentifier"];
// some variable that stores whether to show the indicators
cell.disclosureVisible = self.disclosureIndicatorsVisible;
// Any more setup you need to do with your cell
然后,当您点击按钮更改指示器的可见性时,您有几个选项,具体取决于您尝试执行的操作:
reloadData
,这将导致所有集合视图刷新[self.tableView indexPathsForVisibleRows]
获得的每个可见表视图单元格,使用[cell.collectionView indexPathsForVisibleItems]
获取每个集合视图单元格。然后对执行动画的每个单元格调用自定义方法以显示或隐藏指示器编辑:您在评论中说希望表格视图单元格显示详细信息披露指标。在这种情况下,您可能希望如上所述获取表视图的所有可见单元格,并将其
accessoryType
设置为UITableViewCellAccessoryDetailDisclosureButton
。但是,accessoryType
不是一个可设置动画的属性,因此您可能需要向UITableViewCell
子类添加一个自定义属性,该子类对自定义附件视图的显示和隐藏进行动画处理,然后该视图会对点击做出响应。不完全是您想要的,但逻辑如下:
@interface YourViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *dataArr;
@property (strong, nonatomic) NSMutableArray *checksArr;
@end
@界面YourViewController:UIViewController
@属性(强,非原子)IBUITableView*tableView;
@属性(非原子,强)NSArray*dataArr;
@属性(强,非原子)NSMUTABLEARRY*checksArr;
@结束
在您的视图控制器.m文件中
@implementation YourViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.checksArr = [[NSMutableArray alloc] init];
for (int i=0; i<self.dataArr.count; i++) {
[self.checksArr addObject:[NSNumber numberWithBool:NO]];
}
}
#pragma mark - TableView Datasource
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if([[self.checksArr objectAtIndex:indexPath.row] boolValue]) {
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
}
return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.dataArr count];
}
-(void) btnNavigationBarTapped:(id)sender {
for (int i=0; i<self.dataArr.count; i++) {
[self.checksArr replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:YES]];
}
[self.tableview reloadData];
}
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
self.checksArr=[[NSMutableArray alloc]init];
对于(int i=0;i是否要将“详细信息披露”按钮添加到“表视图”单元格或“集合视图”单元格?添加到“表视图”单元格。每个“表视图”单元格中都有一个集合视图,占据整个屏幕的宽度。我需要每个“集合视图”基本上向左设置动画,然后应显示一个“详细信息披露”按钮。然后,用户应该可以点击披露按钮。编辑我的答案以匹配此评论。