2011-05-23 172 views
0

接收數據我有以下代碼集:自定義UITableViewCell

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

    static NSString *CellIdentifier = @"customCell"; 

    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     NSArray *nibObjs = [[NSBundle mainBundle] loadNibNamed:@"CustomCellView" owner:nil options:nil]; 
     //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

     for(id currentObj in nibObjs) 
     { 
      if([currentObj isKindOfClass:[CustomCell class]]) 
      { 
       cell = (CustomCell *)currentObj; 
      } 

     } 
    } 

    AssessmentDetail * anAssess = [module.assessmentDetails4 objectAtIndex:indexPath.row]; 
    [[cell labelAssessment] setText:anAssess.assessmentName4]; 
    return cell; 
} 

在我的自定義單元格有一個UISlider。我想要做的是使用一個按鈕從每一行中檢索每個UISlider的值,以便我可以獲得總值。

我想過這樣做,但我不是在哪裏從那裏可以肯定的:

- (IBAction) calculateTotal:(id)sender { 

    static NSString *CellIdentifier = @"customCell"; 

    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

} 

感謝您的幫助。

回答

1

週期通過的UITableView的子視圖:

- (IBAction) calculateTotal:(id)sender { 
    NSArray *subViews = [myTableView subviews]; 
    float total; 

    for (int i = 0; i < subViews.count; i++) 
    { 
     id obj = [subViews objectAtIndex:i]; 
     if ([obj isKindOfClass:[CustomCell class]]) 
     { 
       total += [[obj getMySlider] getValue]; 
     } 
    } 

    // do something with total 
} 
+0

感謝完美的作品! – 2011-05-23 01:33:26

+0

需要注意的一件事:如果您的單元格真正可以出租,那麼如果您的單元格多於整頁,則這隻會返回屏幕單元格的值。 – 2011-05-23 14:11:25

+0

感謝理查德,當我嘗試編碼時,我收集了一些信息。再次感謝 – 2011-05-23 19:03:36