Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UITableView 里面,怎么加到动态的cell上去? #5

Closed
Chemprogrammer opened this issue Jan 19, 2018 · 8 comments
Closed

UITableView 里面,怎么加到动态的cell上去? #5

Chemprogrammer opened this issue Jan 19, 2018 · 8 comments

Comments

@Chemprogrammer
Copy link

您好,请问动态的cell怎么加?点击之后消失。就像微信一样。

@rjinxx
Copy link
Owner

rjinxx commented Jan 22, 2018

调用observePath: badgeView: block:

这边的badgeView可以设置成cell的contentView, 然后调整badgeView的offset使其在右边中间显示(默认在右上角)

也可以在cell的相应位置add一个透明的UIImageView, 然后把badgeView设置成这个UIImageView

这边需要注意cell的复用的情况,如果cell复用了,那它对应的小红点keyPath也需要调整了,否则小红点的显示就乱了

cell的复用的情况下可以在endDisplayCell的回调中unObservePath, 然后在willDisPlayCell的时候重新addObservePath

或者如上面说的将小红点显示在UIImageView上,然后每次cellForItemAtIndexPath重新configCell/Data的时候直接把UIImageView删除后重新关联对应的path后new一个

@kthree0830
Copy link

cell上好像不能添加

@rjinxx
Copy link
Owner

rjinxx commented Mar 5, 2018

按照二楼的步骤加呢?

@kthree0830
Copy link

二楼好像也不行的,cell不够充满整个屏幕的没效果

@rjinxx
Copy link
Owner

rjinxx commented Mar 5, 2018

调整下badgeOffset? 或者你贴个testbed出来我看一下

@kthree0830
Copy link

wx20180305-154632
wx20180305-154750
是在设置observe时的frame为0,而且刷新tableview后因为不足屏幕大小,所以还是会创建新的cell

@rjinxx
Copy link
Owner

rjinxx commented Mar 5, 2018

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
                                         forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *badgePath = [self badgePathAtIndexPath:indexPath];
    if (badgePath) {
        // cell.contentView.badgeOffset = CGPointMake(-5, 5);
        [self.badgeController observePath:badgePath badgeView:cell.contentView block:nil];
    }
}

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell
                                              forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *badgePath = [self badgePathAtIndexPath:indexPath];
    if (badgePath) {
        [self.badgeController unobservePath:badgeKeyPath];
        [cell.contentView hideBadge];
    }
}

我们自己的工程里面是这么设置的,你试下呢

@wchnan
Copy link

wchnan commented May 18, 2019

出个 cell 的demo,cell 的应用场景还是蛮多的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants