Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义TableViewCell中的UIButton在选择时不更改值_Ios_Objective C_Parse Platform_Uibutton_Pfobject - Fatal编程技术网

Ios 自定义TableViewCell中的UIButton在选择时不更改值

Ios 自定义TableViewCell中的UIButton在选择时不更改值,ios,objective-c,parse-platform,uibutton,pfobject,Ios,Objective C,Parse Platform,Uibutton,Pfobject,感谢@jsetting32,我有了一个自定义的UITableViewCell,在tableView的底部有按钮。但是,当我单击这些按钮时,selectedState的值没有改变,这使得最终用户很难判断他们是否单击了它 self.likeButton = [UIButton buttonWithType:UIButtonTypeCustom]; [self.likeButton addTarget:self action:@selector(didTapLikeButtonAction:) for

感谢@jsetting32,我有了一个自定义的
UITableViewCell
,在tableView的底部有按钮。但是,当我单击这些按钮时,selectedState的值没有改变,这使得最终用户很难判断他们是否单击了它

self.likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.likeButton addTarget:self action:@selector(didTapLikeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.likeButton setTitle:@"Pray" forState:UIControlStateNormal];
[self.likeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.likeButton setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
[[self.likeButton titleLabel] setFont:[UIFont fontWithName:@"Verdana" size:12.0f]];
[self.cellView addSubview:self.likeButton];

尝试
UIControlStateHighlighted
而不是
UIControlStateSelected

[self.likeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.likeButton setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];

下面是我如何解决按钮问题的。。。您的自定义单元格中应该已经有一个方法可以设置类似的状态。。。事情是这样安排的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellIdentifier = @"cellIdentifier";

    if (indexPath.row == [self.objects count])
        return [self tableView:tableView cellForNextPageAtIndexPath:indexPath];

    PHChatCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[PHChatCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        [cell setDelegate:self];
    }

    [self setCellAttributesWithCell:cell withObject:[self.object objectAtIndex:indexPath.row] withIndexPath:indexPath];

    return cell;
}


- (void)setCellAttributesWithCell:(PHChatCell *)cell withObject:(PFObject *)object withIndexPath:(NSIndexPath *)indexPath
{
    if (object) {
        [cell setChat:object];
        [cell setTag:indexPath.row];
        [cell.likeButton setTag:indexPath.row];

        if ([[PHCache sharedCache] attributesForMessage:object]) {
            [cell setLikeStatus:[[PHCache sharedCache] isMessageLikedByCurrentUser:object]];

            NSString *likeCount = [[[PHCache sharedCache] likeCountForMessage:object] description];
            cell.likeCount.text = ([likeCount isEqualToString:@"1"]) ?
            [NSString stringWithFormat:@"%@ like", likeCount] :
            [NSString stringWithFormat:@"%@ likes", likeCount];

            NSString *commentCount = [[[PHCache sharedCache] commentCountForMessage:object] description];
            cell.commentCount.text = ([commentCount isEqualToString:@"1"]) ?
            [NSString stringWithFormat:@"%@ comment", commentCount] :
            [NSString stringWithFormat:@"%@ comments", commentCount];
            return;
        }

        @synchronized(self) {
            // Put this in your init method
            // self.outstandingSectionHeadersQueries = [NSMutableDictionary dictionary]
            if (![self.outstandingSectionHeaderQueries objectForKey:@(indexPath.row)]) {
                PFQuery *query = [PHUtility queryForActivitiesOnMessage:object cachePolicy:kPFCachePolicyNetworkOnly];
                [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
                    @synchronized(self) {
                        [self.outstandingSectionHeaderQueries removeObjectForKey:@(indexPath.row)];

                        if (error) return;

                        NSMutableArray *likers = [NSMutableArray array];
                        NSMutableArray *commenters = [NSMutableArray array];

                        BOOL isLikedByCurrentUser = NO;

                        for (PFObject *activity in objects) {
                            if ([[activity objectForKey:kPHActivityTypeKey] isEqualToString:kPHActivityTypeLike] && [activity objectForKey:kPHActivityFromUserKey]) {
                                [likers addObject:[activity objectForKey:kPHActivityFromUserKey]];
                            } else if ([[activity objectForKey:kPHActivityTypeKey] isEqualToString:kPHActivityTypeComment] && [activity objectForKey:kPHActivityFromUserKey]) {
                                [commenters addObject:[activity objectForKey:kPHActivityFromUserKey]];
                            }

                            if ([[[activity objectForKey:kPHActivityFromUserKey] objectId] isEqualToString:[[PFUser currentUser] objectId]] &&
                                [[activity objectForKey:kPHActivityTypeKey] isEqualToString:kPHActivityTypeLike]) {
                                isLikedByCurrentUser = YES;
                            }
                        }

                        [[PHCache sharedCache] setAttributesForMessage:object likers:likers commenters:commenters likedByCurrentUser:isLikedByCurrentUser];

                        if (cell.tag != indexPath.row) return;

                        [cell setLikeStatus:[[PHCache sharedCache] isMessageLikedByCurrentUser:object]];

                        NSString *likeCount = [[[PHCache sharedCache] likeCountForMessage:object] description];
                        cell.likeCount.text = ([likeCount isEqualToString:@"1"]) ?
                        [NSString stringWithFormat:@"%@ like", likeCount] : [NSString stringWithFormat:@"%@ likes", likeCount];

                        NSString *commentCount = [[[PHCache sharedCache] commentCountForMessage:object] description];
                        cell.commentCount.text = ([commentCount isEqualToString:@"1"]) ?
                        [NSString stringWithFormat:@"%@ comment", commentCount] : [NSString stringWithFormat:@"%@ comments", commentCount];
                    }
                }];
            }
        }
    }
}


- (void)PHChatCell:(PHChatCell *)cell didTapLikeButton:(UIButton *)button chat:(PFObject *)chat
{
    // Disable the button so users cannot send duplicate requests
    [cell shouldEnableLikeButton:NO];

    //These are private interface properties to handle when the user wants to unlike the prayer
    //when the UIActionsheet is loaded
    self.chat = chat;
    self.likeButton = button;
    self.cell = cell;

    if (button.selected) {
        [[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Unlike" otherButtonTitles:nil] showInView:self.view];
        return;
    }

    BOOL liked = !button.selected;
    [cell setLikeStatus:liked];

    NSString *originalButtonTitle = button.titleLabel.text;
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];

    NSNumber *likeCount = [numberFormatter numberFromString:button.titleLabel.text];
    [button setTitle:@"Liked" forState:UIControlStateNormal];

    [UIView animateWithDuration:0.25 animations:^{
        [cell.likeImage setImage:[UIImage imageNamed:@"ButtonLikeSelected.png"]];
        [cell.likeImage setTransform:CGAffineTransformMakeScale(1.5, 1.5)];
    } completion:^(BOOL finished){
        [UIView animateWithDuration:0.25 animations:^{
            [cell.likeImage setTransform:CGAffineTransformMakeScale(1, 1)];
        }];
    }];

    NSInteger checker = [[cell.likeCount text] integerValue] + 1;
    cell.likeCount.text = (checker == 1) ?
    [NSString stringWithFormat:@"%ld like", (long)checker] :
    [NSString stringWithFormat:@"%ld likes", (long)checker];
    likeCount = [NSNumber numberWithInt:[likeCount intValue] + 1];

    [[PHCache sharedCache] incrementLikerCountForMessage:chat];
    [[PHCache sharedCache] setMessageIsLikedByCurrentUser:chat liked:liked];
    [PHUtility likeMessageInBackground:chat block:^(BOOL succeeded, NSError *error) {
        PHChatCell *actualCell = (PHChatCell *)[self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:button.tag inSection:0]];
        [actualCell shouldEnableLikeButton:YES];
        [actualCell setLikeStatus:succeeded];

        if (!succeeded) {
            [actualCell.likeButton setTitle:originalButtonTitle forState:UIControlStateNormal];
        }
    }];
}
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {

        BOOL liked = !self.likeButton.selected;
        [self.cell setLikeStatus:liked];

        [self.likeButton setTitle:@"Like" forState:UIControlStateNormal];
        [self.cell.likeImage setImage:[UIImage imageNamed:@"ButtonLike.png"]];

        NSInteger checker = [[self.cell.likeCount text] integerValue] - 1;
        self.cell.likeCount.text = (checker == 1) ?
        [NSString stringWithFormat:@"%ld like", (long)checker] :
        [NSString stringWithFormat:@"%ld likes", (long)checker];

        NSString *originalButtonTitle = self.likeButton.titleLabel.text;
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        NSNumber *likeCount = [numberFormatter numberFromString:self.likeButton.titleLabel.text];
        likeCount = [NSNumber numberWithInt:[likeCount intValue] + 1];
        if ([likeCount intValue] > 0) {
            likeCount = [NSNumber numberWithInt:[likeCount intValue] - 1];
        }

        [[PHCache sharedCache] decrementLikerCountForMessage:self.chat];
        [[PHCache sharedCache] setMessageIsLikedByCurrentUser:self.chat liked:NO];
        [PHUtility unlikeMessageInBackground:self.chat block:^(BOOL succeeded, NSError *error) {
            PHChatCell *actualCell = (PHChatCell *)[self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.likeButton.tag inSection:0]];
            [actualCell shouldEnableLikeButton:YES];
            [actualCell setLikeStatus:!succeeded];

            if (!succeeded) {
                [actualCell.likeButton setTitle:originalButtonTitle forState:UIControlStateNormal];
            }
        }];
    }
}
以下是上一段代码(在PHUtility类中声明)中使用的查询方法:

以下是PHCache实现

@interface PHCache()

@property (nonatomic, strong) NSCache *cache;
- (void)setAttributes:(NSDictionary *)attributes forMessage:(PFObject *)message;
@end

@implementation PHCache
@synthesize cache;

#pragma mark - Initialization

+ (id)sharedCache {
    static dispatch_once_t pred = 0;
    __strong static id _sharedObject = nil;
    dispatch_once(&pred, ^{
        _sharedObject = [[self alloc] init];
    });
    return _sharedObject;
}

- (id)init {
    self = [super init];
    if (self) {
        self.cache = [[NSCache alloc] init];
    }
    return self;
}

- (void)clear {
    [self.cache removeAllObjects];
}
- (void)setAttributes:(NSDictionary *)attributes forMessage:(PFObject *)message {
    [self.cache setObject:attributes forKey:[self keyForMessage:message]];
}
- (NSString *)keyForMessage:(PFObject *)message {
    return [NSString stringWithFormat:@"message_%@", [message objectId]];
}

#pragma mark - Global Chat
- (void)setAttributesForMessage:(PFObject *)message
                         likers:(NSArray *)likers
                     commenters:(NSArray *)commenters
             likedByCurrentUser:(BOOL)likedByCurrentUser {
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSNumber numberWithBool:likedByCurrentUser],kPHMessageAttributesIsLikedByCurrentUserKey,
                                @([likers count]),kPHMessageAttributesLikeCountKey,
                                likers,kPHMessageAttributesLikersKey,
                                @([commenters count]),kPHMessageAttributesCommentCountKey,
                                commenters,kPHMessageAttributesCommentersKey,
                                nil];
    [self setAttributes:attributes forMessage:message];
}

- (NSDictionary *)attributesForMessage:(PFObject *)message {
    return [self.cache objectForKey:[self keyForMessage:message]];
}

- (NSNumber *)likeCountForMessage:(PFObject *)message {
    NSDictionary *attributes = [self attributesForMessage:message];
    if (attributes) {
        return [attributes objectForKey:kPHMessageAttributesLikeCountKey];
    }

    return [NSNumber numberWithInt:0];
}

- (NSNumber *)commentCountForMessage:(PFObject *)message {
    NSDictionary *attributes = [self attributesForMessage:message];
    if (attributes) {
        return [attributes objectForKey:kPHMessageAttributesCommentCountKey];
    }

    return [NSNumber numberWithInt:0];
}

- (NSArray *)likersForMessage:(PFObject *)message {
    NSDictionary *attributes = [self attributesForMessage:message];
    if (attributes) {
        return [attributes objectForKey:kPHMessageAttributesLikersKey];
    }

    return [NSArray array];
}

- (NSArray *)commentersForMessage:(PFObject *)message {
    NSDictionary *attributes = [self attributesForMessage:message];
    if (attributes) {
        return [attributes objectForKey:kPHMessageAttributesCommentersKey];
    }

    return [NSArray array];
}

- (void)setMessageIsLikedByCurrentUser:(PFObject *)message liked:(BOOL)liked {
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForMessage:message]];
    [attributes setObject:[NSNumber numberWithBool:liked] forKey:kPHMessageAttributesIsLikedByCurrentUserKey];
    [self setAttributes:attributes forMessage:message];
}

- (BOOL)isMessageLikedByCurrentUser:(PFObject *)message {
    NSDictionary *attributes = [self attributesForMessage:message];
    if (attributes) {
        return [[attributes objectForKey:kPHMessageAttributesIsLikedByCurrentUserKey] boolValue];
    }

    return NO;
}

- (void)incrementLikerCountForMessage:(PFObject *)message {
    NSNumber *likerCount = [NSNumber numberWithInt:[[self likeCountForMessage:message] intValue] + 1];
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForMessage:message]];
    [attributes setObject:likerCount forKey:kPHMessageAttributesLikeCountKey];
    [self setAttributes:attributes forMessage:message];
}

- (void)decrementLikerCountForMessage:(PFObject *)message {
    NSNumber *likerCount = [NSNumber numberWithInt:[[self likeCountForMessage:message] intValue] - 1];
    if ([likerCount intValue] < 0) {
        return;
    }
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForMessage:message]];
    [attributes setObject:likerCount forKey:kPHMessageAttributesLikeCountKey];
    [self setAttributes:attributes forMessage:message];
}

- (void)incrementCommentCountForMessage:(PFObject *)message {
    NSNumber *commentCount = [NSNumber numberWithInt:[[self commentCountForMessage:message] intValue] + 1];
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForMessage:message]];
    [attributes setObject:commentCount forKey:kPHMessageAttributesCommentCountKey];
    [self setAttributes:attributes forMessage:message];
}

- (void)decrementCommentCountForMessage:(PFObject *)message {
    NSNumber *commentCount = [NSNumber numberWithInt:[[self commentCountForMessage:message] intValue] - 1];
    if ([commentCount intValue] < 0) {
        return;
    }
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForMessage:message]];
    [attributes setObject:commentCount forKey:kPHMessageAttributesCommentCountKey];
    [self setAttributes:attributes forMessage:message];
}

- (NSNumber *)messageCountForUser:(PFUser *)user {
    NSDictionary *attributes = [self attributesForUser:user];
    if (attributes) {
        NSNumber *photoCount = [attributes objectForKey:kPHUserAttributesMessageCountKey];
        if (photoCount) {
            return photoCount;
        }
    }

    return [NSNumber numberWithInt:0];
}

- (void)setMessageCount:(NSNumber *)count user:(PFUser *)user {
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForUser:user]];
    [attributes setObject:count forKey:kPHUserAttributesMessageCountKey];
    [self setAttributes:attributes forUser:user];
}
@interface PHCache()
@属性(非原子,强)NSCache*缓存;
-(void)setAttributes:(NSDictionary*)属性formMessage:(PFObject*)消息;
@结束
@PHCache的实现
@综合缓存;
#pragma标记-初始化
+(id)sharedCache{
静态调度\u once\u t pred=0;
__强静态id_sharedObject=nil;
一次发送(和预先发送)^{
_sharedObject=[[self alloc]init];
});
返回共享对象;
}
-(id)init{
self=[super init];
如果(自我){
self.cache=[[NSCache alloc]init];
}
回归自我;
}
-(无效)清除{
[self.cache removeAllObjects];
}
-(void)setAttributes:(NSDictionary*)属性formMessage:(PFObject*)消息{
[self.cache setObject:attributes forKey:[self-keyFormMessage:message]];
}
-(NSString*)KeyFormMessage:(PFObject*)消息{
返回[NSString stringWithFormat:@“消息%@,[message objectId]];
}
#pragma标记-全局聊天
-(void)SetAttributesFormMessage:(PFObject*)消息
喜欢者:(NSArray*)喜欢者
评论者:(NSArray*)评论者
likedByCurrentUser:(BOOL)likedByCurrentUser{
NSDictionary*属性=[NSDictionary Dictionary WithObjectsAndKeys:
[NSNumber numberWithBool:likedByCurrentUser],KPHMessageAttributesIkedByCurrentUserKey,
@([likers count]),kPHMessageAttributesLikeCountKey,
喜欢,KPHMessageAttribute喜欢,
@([commenters count]),kPHMessageAttributesCommentCountKey,
评论员,kPHMessageAttributesCommentersKey,
零];
[self-setAttributes:attributes-forMessage:message];
}
-(NSDictionary*)AttributesFormMessage:(PFObject*)消息{
返回[self.cache objectForKey:[self-keyFormMessage:message]];
}
-(NSNumber*)如CountFormMessage:(PFObject*)消息{
NSDictionary*attributes=[self-attributesForMessage:message];
如果(属性){
返回[attributes objectForKey:kPHMessageAttributesLikeCountKey];
}
返回[NSNumber numberWithInt:0];
}
-(NSNumber*)CommentCountFormMessage:(PFObject*)消息{
NSDictionary*attributes=[self-attributesForMessage:message];
如果(属性){
返回[attributes objectForKey:kPHMessageAttributesCommentCountKey];
}
返回[NSNumber numberWithInt:0];
}
-(NSArray*)likersForMessage:(PFObject*)消息{
NSDictionary*attributes=[self-attributesForMessage:message];
如果(属性){
返回[attributes objectForKey:KPHMessageAttributesLikerKey];
}
返回[NSArray数组];
}
-(NSArray*)注释器FormMessage:(PFObject*)消息{
NSDictionary*attributes=[self-attributesForMessage:message];
如果(属性){
返回[attributes objectForKey:kPHMessageAttributesCommentersKey];
}
返回[NSArray数组];
}
-(void)setMessageIsLikedByCurrentUser:(PFObject*)喜欢的消息:(BOOL)喜欢的{
NSMutableDictionary*attributes=[NSMutableDictionary Dictionary WithDictionary:[self AttributesFormMessage:message]];
[attributes setObject:[NSNumber numberWithBool:liked]forKey:KPHMessageAttributesLiskedBycurrentUserKey];
[self-setAttributes:attributes-forMessage:message];
}
-(BOOL)isMessageLikedByCurrentUser:(PFObject*)消息{
NSDictionary*attributes=[self-attributesForMessage:message];
如果(属性){
返回[[attributes objectForKey:KPHMessageAttributesLislekedBycurrentUserKey]布尔值];
}
返回否;
}
-(void)IncrementLikerCountFormMessage:(PFObject*)消息{
NSNumber*likerCount=[NSNumber numberWithInt:[[self-LikeCountFormMessage:message]intValue]+1];
NSMutableDictionary*attributes=[NSMutableDictionary Dictionary WithDictionary:[self AttributesFormMessage:message]];
[attributes setObject:likerCount forKey:kPHMessageAttributesLikeCountKey];
[self-setAttributes:attributes-forMessage:message];
}
-(void)递减LikerCountFormMessage:(PFObject*)消息{
NSNumber*likerCount=[NSNumber numberWithInt:[[self-LikeCountFormMessage:message]intValue]-1];
如果([likerCount intValue]<0){
返回;
}
NSMutableDictionary*attributes=[NSMutableDictionary Dictionary WithDictionary:[self AttributesFormMessage:message]];
[attributes setObject:likerCount forKey:kPHMessageAttributesLikeCountKey];
[self-setAttributes:attributes-forMessage:message];
}
-(void)IncrementCommentCountFormMessage:(PFObject*)消息{
NSNumber*commentCount=[NSNumber numberWithInt:[[self-CommentCountFormMessage:message]intValue]+1];
NSMutableDictionary*attributes=[NSMutableDictionary Dictionary WithDictionary:[self AttributesFormMessage:message]];
[attributes setObject:commentCount forKey:kPHMessageAttributesCommentCountKey];
[self-setAttributes:attributes-forMessage:message];
}
-(void)DecrementCommentCountFormMessage:(PFObject*)消息{
NSNumber*commentCount=[NSNumber NUMBER WITHINT:[[self-CommentCountFormMessage:message]intValue]-1];
如果([commentCount intValue]<0){
返回;
}
NSMutableDictionary*属性=[NSMutableDictionary Dictionary WithDictiona]
@interface PHCache()

@property (nonatomic, strong) NSCache *cache;
- (void)setAttributes:(NSDictionary *)attributes forMessage:(PFObject *)message;
@end

@implementation PHCache
@synthesize cache;

#pragma mark - Initialization

+ (id)sharedCache {
    static dispatch_once_t pred = 0;
    __strong static id _sharedObject = nil;
    dispatch_once(&pred, ^{
        _sharedObject = [[self alloc] init];
    });
    return _sharedObject;
}

- (id)init {
    self = [super init];
    if (self) {
        self.cache = [[NSCache alloc] init];
    }
    return self;
}

- (void)clear {
    [self.cache removeAllObjects];
}
- (void)setAttributes:(NSDictionary *)attributes forMessage:(PFObject *)message {
    [self.cache setObject:attributes forKey:[self keyForMessage:message]];
}
- (NSString *)keyForMessage:(PFObject *)message {
    return [NSString stringWithFormat:@"message_%@", [message objectId]];
}

#pragma mark - Global Chat
- (void)setAttributesForMessage:(PFObject *)message
                         likers:(NSArray *)likers
                     commenters:(NSArray *)commenters
             likedByCurrentUser:(BOOL)likedByCurrentUser {
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSNumber numberWithBool:likedByCurrentUser],kPHMessageAttributesIsLikedByCurrentUserKey,
                                @([likers count]),kPHMessageAttributesLikeCountKey,
                                likers,kPHMessageAttributesLikersKey,
                                @([commenters count]),kPHMessageAttributesCommentCountKey,
                                commenters,kPHMessageAttributesCommentersKey,
                                nil];
    [self setAttributes:attributes forMessage:message];
}

- (NSDictionary *)attributesForMessage:(PFObject *)message {
    return [self.cache objectForKey:[self keyForMessage:message]];
}

- (NSNumber *)likeCountForMessage:(PFObject *)message {
    NSDictionary *attributes = [self attributesForMessage:message];
    if (attributes) {
        return [attributes objectForKey:kPHMessageAttributesLikeCountKey];
    }

    return [NSNumber numberWithInt:0];
}

- (NSNumber *)commentCountForMessage:(PFObject *)message {
    NSDictionary *attributes = [self attributesForMessage:message];
    if (attributes) {
        return [attributes objectForKey:kPHMessageAttributesCommentCountKey];
    }

    return [NSNumber numberWithInt:0];
}

- (NSArray *)likersForMessage:(PFObject *)message {
    NSDictionary *attributes = [self attributesForMessage:message];
    if (attributes) {
        return [attributes objectForKey:kPHMessageAttributesLikersKey];
    }

    return [NSArray array];
}

- (NSArray *)commentersForMessage:(PFObject *)message {
    NSDictionary *attributes = [self attributesForMessage:message];
    if (attributes) {
        return [attributes objectForKey:kPHMessageAttributesCommentersKey];
    }

    return [NSArray array];
}

- (void)setMessageIsLikedByCurrentUser:(PFObject *)message liked:(BOOL)liked {
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForMessage:message]];
    [attributes setObject:[NSNumber numberWithBool:liked] forKey:kPHMessageAttributesIsLikedByCurrentUserKey];
    [self setAttributes:attributes forMessage:message];
}

- (BOOL)isMessageLikedByCurrentUser:(PFObject *)message {
    NSDictionary *attributes = [self attributesForMessage:message];
    if (attributes) {
        return [[attributes objectForKey:kPHMessageAttributesIsLikedByCurrentUserKey] boolValue];
    }

    return NO;
}

- (void)incrementLikerCountForMessage:(PFObject *)message {
    NSNumber *likerCount = [NSNumber numberWithInt:[[self likeCountForMessage:message] intValue] + 1];
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForMessage:message]];
    [attributes setObject:likerCount forKey:kPHMessageAttributesLikeCountKey];
    [self setAttributes:attributes forMessage:message];
}

- (void)decrementLikerCountForMessage:(PFObject *)message {
    NSNumber *likerCount = [NSNumber numberWithInt:[[self likeCountForMessage:message] intValue] - 1];
    if ([likerCount intValue] < 0) {
        return;
    }
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForMessage:message]];
    [attributes setObject:likerCount forKey:kPHMessageAttributesLikeCountKey];
    [self setAttributes:attributes forMessage:message];
}

- (void)incrementCommentCountForMessage:(PFObject *)message {
    NSNumber *commentCount = [NSNumber numberWithInt:[[self commentCountForMessage:message] intValue] + 1];
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForMessage:message]];
    [attributes setObject:commentCount forKey:kPHMessageAttributesCommentCountKey];
    [self setAttributes:attributes forMessage:message];
}

- (void)decrementCommentCountForMessage:(PFObject *)message {
    NSNumber *commentCount = [NSNumber numberWithInt:[[self commentCountForMessage:message] intValue] - 1];
    if ([commentCount intValue] < 0) {
        return;
    }
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForMessage:message]];
    [attributes setObject:commentCount forKey:kPHMessageAttributesCommentCountKey];
    [self setAttributes:attributes forMessage:message];
}

- (NSNumber *)messageCountForUser:(PFUser *)user {
    NSDictionary *attributes = [self attributesForUser:user];
    if (attributes) {
        NSNumber *photoCount = [attributes objectForKey:kPHUserAttributesMessageCountKey];
        if (photoCount) {
            return photoCount;
        }
    }

    return [NSNumber numberWithInt:0];
}

- (void)setMessageCount:(NSNumber *)count user:(PFUser *)user {
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[self attributesForUser:user]];
    [attributes setObject:count forKey:kPHUserAttributesMessageCountKey];
    [self setAttributes:attributes forUser:user];
}
self.likeButton.selected = !self.likeButton.selected;
[self.likeButton setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
[self.likeButton addTarget:self action:@selector(select:) forControlEvents:UIControlEventTouchUpInside];
-(IBAction)onSelectCellClicked:(id)sender {
   if(self.yourButton.selected) {
      self.yourButton.selected = NO;
    } else {
      self.yourButton.selected = YES;
    }
}
@protocol CustomCellDelegate <NSObject>
@end

@interface CustomCell : UITableViewCell
@property (strong, nonatomic) NSObject<CustomCellDelegate>* delegate;

@end