我在使用PFRelation的tableview页脚内部创建了一个Like按钮(就像FaceBook或Twitter),但出于某种原因,当任何用户按下Button时,应用程序或解析中没有任何内容,请帮助请任何想法。谢谢你预先
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
static NSString *CellIdentifier = @"section";
UITableViewCell *section = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIButton *LikeButton =(UIButton *) [section viewWithTag:1];
UITapGestureRecognizer *gesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(taponbutton:)];
[LikeButton setUserInteractionEnabled:YES];
[LikeButton addGestureRecognizer:gesture];
[section addSubview:LikeButton];
return section;
}
-(void)taponbutton:(UIGestureRecognizer *)gesture{
PFUser *user=[PFUser currentUser];
PFObject *object =[object objectForKey:@"newspaper"];
PFRelation *relation=[object relationForKey:@"like"];
[object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(succeeded)
{
[relation addObject:object];
[user saveInBackground];
}
}];
}
-(void)getthelikequery{
PFQuery * query=[PFQuery queryWithClassName:@"like"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if(objects)
{
for (int i=0;i<_arrayofobjects.count;i++ )
{
self.arrayofobjects=objects;
}
_arrayofobjects.count;
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(133, 12, 42, 21)];
label.text=[NSString stringWithFormat:@"%lu",(unsigned long)_arrayofobjects.count];
// this label needs to return the #of people who like the article
}
}];
}
答案 0 :(得分:0)
根据您的代码。您不必在按钮上添加点按手势。你应该在按钮上添加目标。
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 44.0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *viewHeader = [[UIView alloc]init];
viewHeader.frame = CGRectMake(0, 0, 320, 44.0);//set frame here
viewHeader.backgroundColor = [UIColor whiteColor];
//create like button
UIButton * likeButton = [[UIButton alloc]initWithFrame:CGRectMake(65.0,10.0, 320.0-130.0, 30.0)];//set your frame here
likeButton.tag = section;
[likeButton setTitle:@"Like" forState:UIControlStateNormal];
[likeButton addTarget:self action:@selector(taponbutton:) forControlEvents:UIControlEventTouchUpInside];
[viewHeader addSubview:likeButton];
return viewHeader;
}
// Implement Like button.
-(void)taponbutton:(UIButton *)likeButton
{
NSLog(@"%ld",(long)likeButton.tag);
// now do what you want. here you'll get your section.
}
也许这会对你有帮助。