我的TableView
由"n"
个部分组成,每个部分包含8到10个问题,
这里的问题是当我在Section-1
和Row-1
作为假设"Yes"
选项回答时,
这个“是”再次复制第2节第3行中相同的“是”选项。
任何人都可以解决,是什么原因?
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [headersArray count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [headersArray count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[dicc valueForKey:[headersArray objectAtIndex:section]]count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (isTagsExapanded && isSelectedRowIndex == indexPath.row && isSelectedSectionIndex == indexPath.section) {
return 255;
}else{
return 85;
}
return 0;
}
//cell for row at indexpath
----------------------------------------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
UILabel*titleUIL=(UILabel *) [cell.contentView viewWithTag:1];
UILabel*no=(UILabel *) [cell.contentView viewWithTag:10];
UILabel*numLab=(UILabel *) [cell.contentView viewWithTag:22];
UITextView *txt=(UITextView *)[cell.contentView viewWithTag:21];
txt.delegate = self;
titleUIL.text = [[dicc valueForKey:[headersArray objectAtIndex:indexPath.section]]objectAtIndex:indexPath.row];
UIButton *notappBTN=(UIButton *)[cell.contentView viewWithTag:112];
UIButton *yesBTN=(UIButton *)[cell.contentView viewWithTag:100];
UIButton *NOBTN=(UIButton *)[cell.contentView viewWithTag:111];
// [yesBTN setBackgroundColor:[UIColor whiteColor]];
//
// [NOBTN setBackgroundColor:[UIColor redColor]];
//
// [notappBTN setBackgroundColor:[UIColor whiteColor]];
NSInteger sectionCount =0;
if (indexPath.section != 0)
{
for (int q =0; q< indexPath.section; q++) {
sectionCount =sectionCount+[[dicc valueForKey:[headersArray objectAtIndex:q]]count];
}
sectionCount =sectionCount + indexPath.row;
}
else{
sectionCount =sectionCount + indexPath.row;
}
if ([answersARRAY[sectionCount] isEqualToString:@"1"]) {
[yesBTN setBackgroundColor:[UIColor colorWithRed:0.23 green:0.62 blue:0.23 alpha:1.0]];
[NOBTN setBackgroundColor:[UIColor whiteColor]];
[notappBTN setBackgroundColor:[UIColor whiteColor]];
}
else if ([answersARRAY[sectionCount] isEqualToString:@"-1"])
{
[NOBTN setBackgroundColor:[UIColor colorWithRed:1.00 green:0.02 blue:0.02 alpha:1.0]];
[yesBTN setBackgroundColor:[UIColor whiteColor]];
[notappBTN setBackgroundColor:[UIColor whiteColor]];
}
else if ([answersARRAY[sectionCount] isEqualToString:@"0"]){
[NOBTN setBackgroundColor:[UIColor whiteColor]];
[notappBTN setBackgroundColor:[UIColor colorWithRed:0.97 green:0.56 blue:0.02 alpha:1.0]];
[yesBTN setBackgroundColor:[UIColor whiteColor]];
}
numLab.text= [NSString stringWithFormat:@"%i",indexPath.row +1];
return cell;
}