0

我在表格视图中有两个部分,当用户单击任何单元格时,它会显示详细数据,但问题是当用户从第一部分选择任何选项时,它会显示索引 3,而从第二部分开始,它只显示 6,我有 3 个值在每个部分中,我希望当我单击索引时它可能会显示索引值而不是最后三个值

contentID 为所有平均最后值显示 3

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    ObjectData *theCellData = [resultArray objectAtIndex:indexPath.row];
    userName=@"Jamshed";
    contentID=theCellData.content_ID;
    status=@"On";

    NSString*type=theCellData.content_Type;

    if ([type isEqualToString:@"Video" ]) 
        {
      [self playVideo];
    }

}




 -(void)addToLearning{


NSLog(@"Content ID Learning %@",contentID);


NSDate *StrDate = [NSDate date];
NSDateFormatter *Dateformat = [[NSDateFormatter alloc]init];
[Dateformat setDateFormat:@"DD-MM-YYYY HH:mm:SS"];
NSMutableString *DateStr = [Dateformat stringFromDate:StrDate];
addedDate=DateStr;


NSString *post =[[NSString alloc] initWithFormat:@"user_Name=%@&content_ID=%@&added_Date=%@&status=%@",userName,contentID,addedDate,status];

NSURL *url=[NSURL URLWithString:@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/myLearning.php"];

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];


NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@",data);

}

4

2 回答 2

0

UIButton在你的Tapped Method中写下以下 coed 。

-(void) ButtonTapped:(UIButton *) sender
{
        NSIndexPath *indexpathNew = [self.tblView indexPathForCell:(UITableViewCell *)[sender superview]];

      NSLog(@"%@",indexpathNew.row);
}

indexpathNew是单元格选定按钮的返回indextPath

试试我的代码,我可能对你有帮助。

于 2013-03-19T06:20:58.133 回答
0

自定义单元格上的按钮代码

代码 ::

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

   .......

   UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
   [button addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];

   [button setTag:indexPath.row];
   [cell.contentView addSubview:button];

   .........
}

点击方法::

-(IBAction)onClick:(id)sender{

    NSLog(@"Tag :===> %d", [sender tag]);

    ObjectData *theCellData = [resultArray objectAtIndex:[sender tag]];
    contentID = theCellData.content_ID;
    NSLog(@"ID ===> %@", cotentID);   
 }

希望,它可以帮助你。

谢谢。

于 2013-03-19T06:27:00.140 回答