#objective-c #xcode #uitableview #custom-cell
#objective-c #xcode #uitableview #пользовательская ячейка
Вопрос:
У меня есть следующий набор кода:
- (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
}
Комментарии:
1. Следует отметить одну вещь: если у вас действительно есть ячейки, которые можно исключить из очереди, то при наличии ячеек более чем на полной странице будут возвращены только значения ячеек на экране.
2. Спасибо, Ричард, я вроде как понял это, когда пробовал код. Еще раз спасибо