Ios 应为表达式并添加额外的括号

Ios 应为表达式并添加额外的括号,ios,objective-c,Ios,Objective C,好吧,我已经连续几天在做这个了,我似乎不明白为什么我一直得到预期的表达式,为什么Xcode希望我在代码周围添加额外的括号。任何帮助都将不胜感激 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if (section == self.objects.count) { return nil; } static NSStri

好吧,我已经连续几天在做这个了,我似乎不明白为什么我一直得到预期的表达式,为什么Xcode希望我在代码周围添加额外的括号。任何帮助都将不胜感激

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == self.objects.count)
    {
        return nil;
    }
    static NSString *CellIdentifier    = @"SectionHeaderCell";
    UITableViewCell *sectionHeaderView = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    UILabel *userName           = (UILabel *)[sectionHeaderView viewWithTag:1];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

    [dateFormat setDateFormat:@"EEE, MMM d, h:mm a"];

    UILabel *dateLabel = (UILabel *)[sectionHeaderView viewWithTag:2];

    PFObject *post = [self.objects objectAtIndex:section];
    PFUser *user   = [post objectForKey:@"username"];
    userName.text  = user.username;

    //follow button
    //problem is here
    LikeButton *LikeButton  = (LikeButton *)[sectionHeaderView viewWithTag:3];
    //^^^^
    LikeButton.delegate     = self;
    LikeButton.sectionIndex = section;



    if (!self.likeArray || [user.objectId isEqualToString:[PFUser currentUser].objectId])
    {
        LikeButton.hidden = YES;
    }
    else
    {
        LikeButton.hidden = NO;
        NSInteger indexOfMatchedObject = [self.likeArray indexOfObject:user.objectId];
        if (indexOfMatchedObject == NSNotFound)
        {
            LikeButton.selected = NO;
        }
        else
        {
            LikeButton.selected = YES;
        }
    }
    return sectionHeaderView;
}

我在你的代码中看到了很多问题

LikeButton *LikeButton = (LikeButton *)[sectionHeaderView viewWithTag:3];
您声明了与类名相同的变量名,这就是为什么会出现错误。改为:

LikeButton *likeBtn = (LikeButton *)[sectionHeaderView viewWithTag:3];

为什么要在viewForHeaderInSection:中对单元格进行出列cellForRowAtIndexPath:方法?此错误具体显示在哪一行?请将其编辑到您的问题中。请修正您的缩进,以便人们能够正确阅读。您认为使用实例变量作为类的确切名称是一个好主意吗?LikeButton*LikeButton哪一行被识别为有错误?????@rmaddy-不太好。是的,我稍后会在代码中实现这一点,非常感谢您帮助我解决我的错误。当我们限制为六个字符的名称时,我们曾经将button缩写为btn。@Zaph:我命名它是因为键入LikeButton时,有可能自动完成时会弹出类名,如按钮