我在我的按钮中创建了一些代码来在我的按钮之间切换,cell identifier
但显然我需要设置和初始单元格标识符,其中的初始单元格标识符是小图标,所以我将如何删除该单元格标识符并用另一个替换它一次按钮被点击。我目前的代码如下:
GroupsViewController.m
#import "GroupsViewController.h"
#import "CustomCell.h"
@interface GroupsViewController ()
{
NSArray *arrayOfImages;
NSArray *arrayOfDescriptions;
}
@end
@implementation GroupsViewController
{
NSString *reuseIdentifier;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[self GroupsCollectionView]setDataSource:self];
[[self GroupsCollectionView]setDelegate:self];
reuseIdentifier= @"SmallIcon";
arrayOfImages = [[NSArray alloc]initWithObjects:@"?.png", nil];
arrayOfDescriptions = [[NSArray alloc]initWithObjects:@"?", nil];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [arrayOfDescriptions count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
[[cell IconImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];
[[cell IconLabel]setText:[arrayOfDescriptions objectAtIndex:indexPath.item]];
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
//Dispose of any resources that can be recreated.
}
- (IBAction)cellToggleAction:(id)sender {
if([reuseIdentifier isEqualToString:@"SmallIcon"])
reuseIdentifier=@"ListView";
else if
([reuseIdentifier isEqualToString:@"ListView"])
reuseIdentifier=@"LargeIcon";
else if
([reuseIdentifier isEqualToString:@"LargeIcon"])
reuseIdentifier=@"SmallIcon";
[self.GroupsCollectionView reloadData];
}
@end
自定义单元格.h
#import <UIKit/UIKit.h>
@interface CustomCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIImageView *IconImage;
@property (weak, nonatomic) IBOutlet UILabel *IconLabel;
@end
我认为这与我在中设置有关reuseIdentifier
,
- (void)viewDidLoad
因此我没有收到任何错误,因此我没有设置错误,所以我真正要求的是一种设置初始重用idzntifier并将其替换为以下内容的方法当我在按钮点击之间切换时。
如果有人能指出我在每次单击按钮时添加图标图像的正确方向,那也会很有帮助。
当我单击下图所示的按钮时会出现问题,单元格本身会发生变化,但初始单元格标识符保持不变。