gpt4 book ai didi

ios - UICollectionView 单元格在滚动时消失

转载 作者:可可西里 更新时间:2023-11-01 06:24:24 45 4
gpt4 key购买 nike

我有两个 collectionView。 header 中的一个 collectionViewController 和另一个 collectionView。当我向下滚动 collectionViewController 时,标题 collectionView 的 collectionView 单元格消失了。 header 中还有一个 segControl 可以更改 collectionViewController 单元格,这也会使 header collectionView 单元格消失。当 Controller 出现时,所有单元格都存在,但是当我选择 segControl 时,标题 Collection View 单元格消失。 collectionViewController 工作正常,只是 header 中的那个弄乱了。

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (collectionView == self.collectionView) {
return [self.dataArray count];
}
return [self.groupArray count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

if (collectionView != self.collectionView) {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"socialCell" forIndexPath:indexPath];
PFObject *group = [self.groupArray objectAtIndex:indexPath.row];
UILabel *label = (UILabel *) [cell viewWithTag:55];
label.text = [group objectForKey:@"Title"];
return cell;
}

userPostCell *postCell = (userPostCell *) [collectionView dequeueReusableCellWithReuseIdentifier:@"postCell" forIndexPath:indexPath];
userPictureCell *pictureCell = (userPictureCell *) [collectionView dequeueReusableCellWithReuseIdentifier:@"pictureCell" forIndexPath:indexPath];
userEventCell *eventCell = (userEventCell *) [collectionView dequeueReusableCellWithReuseIdentifier:@"eventCell" forIndexPath:indexPath];

PFObject *temp = [self.dataArray objectAtIndex:indexPath.row];
if (self.dataArray == self.postsArray) {

postCell.postLabel.text = [temp objectForKey:@"stringPost"];
[self changeToCircle:postCell.profileImage];
if ([temp objectForKey:@"Event"] == nil) {
[postCell.noEventNameButton setTitle:[temp objectForKey:@"User_Name"] forState:UIControlStateNormal];
postCell.noEventNameButton.tag = indexPath.row;
postCell.nameButton.hidden = true;
postCell.noEventNameButton.hidden = false;
}
else{
[postCell.nameButton setTitle:[temp objectForKey:@"User_Name"] forState:UIControlStateNormal];
postCell.nameButton.tag = indexPath.row;
postCell.noEventNameButton.hidden = true;
postCell.nameButton.hidden = false;

//[postCell.eventButton addTarget:self action:@selector(eventPage:) forControlEvents:UIControlEventTouchUpInside];

}
[postCell.eventButton setTitle:[temp objectForKey:@"Event"] forState:UIControlStateNormal];

NSString *createdTime = [NSDateFormatter localizedStringFromDate: temp.createdAt dateStyle: NSDateFormatterNoStyle timeStyle: NSDateFormatterShortStyle];
[postCell.timeButton setTitle:createdTime forState:UIControlStateNormal];

PFFile *imageFile = [temp objectForKey:@"profileImage"];
NSData *data = [imageFile getData];
postCell.profileImage.image = [UIImage imageWithData:data];

NSArray *likeArray = [temp objectForKey:@"likes"];
NSString *likeString = [NSString stringWithFormat:@"%lu Likes", (unsigned long)likeArray.count];
if ([likeArray containsObject:[PFUser currentUser].objectId]) {
postCell.likeButton.hidden = true;
}
else{
postCell.likeButton.hidden = false;
}

NSArray *commentArray = [temp objectForKey:@"Comments"];
NSString *commentString = [NSString stringWithFormat:@"%lu Comments", (unsigned long)commentArray.count];

[postCell.likesButton setTitle:likeString forState:UIControlStateNormal];
[postCell.commentsButton setTitle:commentString forState:UIControlStateNormal];

postCell.eventButton.tag = indexPath.row;
postCell.likeButton.tag = indexPath.row;
postCell.commentsButton.tag = indexPath.row;
postCell.likesButton.tag = indexPath.row;

[postCell.likesButton addTarget:self action:@selector(likesPage:) forControlEvents:UIControlEventTouchUpInside];
[postCell.likeButton addTarget:self action:@selector(like:) forControlEvents:UIControlEventTouchUpInside];
[postCell.commentsButton addTarget:self action:@selector(commentsPage:) forControlEvents:UIControlEventTouchUpInside];
[postCell setUserInteractionEnabled:YES];
return postCell;

}
if (self.dataArray == self.personImages) {
UIImage *personImage = [self.dataArray objectAtIndex:indexPath.row];
pictureCell.userImage.image = personImage;
return pictureCell;
}
if (self.dataArray == self.eventsArray) {
[eventCell.userEvent setTitle:[temp objectForKey:@"Title"] forState:UIControlStateNormal];
eventCell.userEvent.tag = indexPath.row;
[eventCell.userEvent addTarget:self action:@selector(eventPage:) forControlEvents:UIControlEventTouchUpInside];

[eventCell.userGroup setTitle:[temp objectForKey:@"Group_Name"] forState:UIControlStateNormal];
eventCell.userGroup.tag = indexPath.row;
[eventCell.userGroup addTarget:self action:@selector(groupPage:) forControlEvents:UIControlEventTouchUpInside];
return eventCell;
}
return postCell;

分段方法:

- (IBAction)segControl:(id)sender {
UISegmentedControl *segment = (UISegmentedControl *) sender;

if (segment.selectedSegmentIndex == 0) {
self.dataArray = self.postsArray;
[self.collectionView reloadData];
}
if (segment.selectedSegmentIndex == 1) {
self.dataArray = self.personImages;
[self.collectionView reloadData];
}
if (segment.selectedSegmentIndex == 2) {
self.dataArray = self.eventsArray;
[self.collectionView reloadData];
}

最佳答案

来晚了,但这对其他人有帮助

我也有类似的问题,我只是更换了[self.myCollectionView reloadData][self.myCollectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];刷新 Collection View 并显示所有单元格,您可以尝试一下。

关于ios - UICollectionView 单元格在滚动时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28206088/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com