Ich konnte nicht herausfinden, warum die Bildlaufansicht nicht gescrollt wird, während die current_set-Variable erhöht wird. Was ist die genaue Position, um den Code zum Scrollen von UIScrollView zu schreiben, wenn es eine Unteransicht von UITableView ist?Wie scrollt UIScrollView programmgesteuert, was ist eine Unteransicht der benutzerdefinierten UITableViewCell?
Hier ist mein Code:
Die Definition für Tableview: cellForRowAtIndexPath: Methode:
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier=[NSString stringWithFormat:@"regularExerciseCell%li",indexPath.row];
RegularExerciseCell *cell=[tableView1 dequeueReusableCellWithIdentifier:cellIdentifier];
if(!cell)
{
[tableView1 registerNib:[UINib nibWithNibName:@"RegularExerciseCell" bundle:nil] forCellReuseIdentifier:@"regularExerciseCell"];
cell=[tableView1 dequeueReusableCellWithIdentifier:@"regularExerciseCell"];
}
NSLog(@"cellForRow At indexPath %li",indexPath.row);
return cell;
}
Hier ist die Definition für Tableview: willDisplayCell: forRowAtIndexPath: Methode
-(void)tableView:(UITableView *)tableView willDisplayCell:(RegularExerciseCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectedIndex==indexPath.row)
{
cell.routineViewCard.hidden=NO;
//SCROLL VIEW
float scrollView_width=[UIScreen mainScreen].bounds.size.width;
cell.setsScrollView.tag=indexPath.row;
totalSetsInActiveExercise=[array count];
for (int k=0; k<=totalSetsInActiveExercise; k++)
{
[cell.setsScrollView addSubview:[self subviewOfScrollView:scrollView_width]];
}
cell.setsScrollView.contentSize = CGSizeMake(scrollView_width*([workoutViewSetData count]+1),cell.setsScrollView.frame.size.height);
if(condition) //this condition may be true or false depending upon the scenario
{
[self moveToNextSet:indexPath.row and:@"left"];
}
}
else
{
cell.routineViewCard.hidden=YES;
}
}
Die Methode, die tatsächlich Scrolling ist Ansicht
-(void)moveToNextSet:(long)sender_tag and:(NSString*)direction
{
NSIndexPath *indexPath=[NSIndexPath indexPathForItem:sender_tag inSection:1];
RegularExerciseCell *cell=(RegularExerciseCell*) [workoutTableView cellForRowAtIndexPath:indexPath];
if ([direction isEqualToString:@"right"])
{
if(current_set!=0)
current_set--;
}
else if([direction isEqualToString:@"left"])
{
current_set++;
}
CGRect frame = CGRectMake((cell.setsScrollView.bounds.size.width*(current_set)),0,cell.setsScrollView.bounds.size.width,cell.setsScrollView.bounds.size.height);
[cell.setsScrollView scrollRectToVisible:frame animated:YES];
}
Ich würde den Code verwenden, den Sie in 'WillDisplayCell: forRowAtIndexPath:' haben und fügen Sie es mit dem 'CellForIndexPath' könnte dies versuchen – ErickES7