2011-06-17 140 views
0

我有泰伯维这表明在Facebook上发表评论的价值。我在Array中获得注释,在第二个数组中注释Id ..我在tableview单元格中使用了一个uibutton。在那个按钮上,我想获得特殊评论的评论ID,以便我可以将该ID传递到喜欢的方法..但它总是采取ID的最后一条评论..我如何评论Button.tag属性的ID,我的代码是:UITable视图button.tag得到

- (NSInteger)tableView:(UITableView *)atableView numberOfRowsInSection:(NSInteger)section { 

     return [[facebook comments] count]; 
    } 


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

     static NSString *CellIdentifier = @"Cell"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
     } 

    like = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

     like.frame = CGRectMake(60, 70, 40, 20); 

     [like setTitle:@"like" forState:UIControlStateNormal]; 
     [like setTag:indexPath.row]; 
     [like addTarget:self action:@selector(likeComment) forControlEvents:UIControlEventTouchUpInside]; 

     [cell.contentView addSubview:like]; 

     ; 


     cell.textLabel.font = [UIFont fontWithName:@"Arial" size:10.0]; 

     cell.detailTextLabel.font = [UIFont fontWithName:@"Arial" size:12.0]; 

     cell.textLabel.text = [[facebook commentId]objectAtIndex:indexPath.row];  

     cell.detailTextLabel.text = [[facebook comments]objectAtIndex:indexPath.row]; 

     NSLog(@"%@ person like this",[facebook likesCount]); 


     NSLog(@"%@ person like this comment",[facebook commentLikes]); 



     return cell; 
    } 

    - (void)likeComment { 

     NSString *idStr = [NSString stringWithFormat:@"%@/likes",[[facebook commentId]objectAtIndex:like.tag]]; 



     [fbGraph doGraphPost:idStr withPostVars:nil]; 

     UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"You like this" 
                 message:@"" delegate:nil 
              cancelButtonTitle:@"Ok" otherButtonTitles:nil ]; 

     [alert show]; 
     [alert release]; 




} 

请帮

回答

1

的问题,你所面临的,因为你总是使用最后like按钮

你需要做出一些改变,像likeComment:函数名称追加一个。

[like addTarget:self action:@selector(likeComment:) forControlEvents:UIControlEventTouchUpInside]; 

并修改您的likeComment方法,如下所示。

- (void)likeComment:(id) sender { 

     UIButton* myLikeButton = (UIButton*)sender; 
     NSString *idStr = [NSString stringWithFormat:@"%@/likes",[[facebook commentId]objectAtIndex:myLikeButton.tag]]; 



     [fbGraph doGraphPost:idStr withPostVars:nil]; 

     UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"You like this" 
                 message:@"" delegate:nil 
              cancelButtonTitle:@"Ok" otherButtonTitles:nil ]; 

     [alert show]; 
     [alert release]; 
} 
+0

感谢您的帮助..我改变like.tag到MyLikeButton.tag – iProgrammer 2011-06-17 07:25:33

+0

@Pallavi:好,我想改变这种状况,感谢 – Jhaliya 2011-06-17 07:28:03

+0

ok.have你使用Facebook的图形api.Because我没有得到所有评论,它只显示几个评论 – iProgrammer 2011-06-17 07:28:53