自定义UITableViewCell
问题描述:
接收数据我有以下代码集:自定义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];
}
感谢您的帮助。
答
周期通过的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
}
感谢完美的作品! – 2011-05-23 01:33:26
需要注意的一件事:如果您的单元格真正可以出租,那么如果您的单元格多于整页,则这只会返回屏幕单元格的值。 – 2011-05-23 14:11:25
感谢理查德,当我尝试编码时,我收集了一些信息。再次感谢 – 2011-05-23 19:03:36