2011-06-17 89 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