2016-04-15 13 views
0

私はUITableViewのサブビュー時に、UIScrollViewをスクロールするコードを書く正確な位置は何ですか?current_set変数が増加しているのに対し、スクロールビューがスクロールされていない理由を理解できませんでしたか?ここでUIScrollViewをプログラムでスクロールする方法は、カスタムUITableViewCellのサブビューですか?

が私のコードです:

のtableViewの定義:cellForRowAtIndexPath:方法:

- (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; 
} 

ここではのtableViewの定義です:willDisplayCell:forRowAtIndexPath:方法

-(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; 
} 
} 

実際にスクロールしているスクロール方法ビュー

-(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]; 
} 
+0

私は 'willDisplayCell:forRowAtIndexPath:'にあるコードを使用して、 'cellForIndexPath'を入れて試してみてください – ErickES7

答えて

0

の代わりに「でscrollRectToVisible」メソッドを使用して、あなたはScrollViewの「contentOffset」を設定しようとするかもしれません。

[cell.setsScrollView setContentOffset:CGPointMake(x, 0) animated:true]; 

xはあなたがscrollviewのスクロールをしたいポイントです。正面である(0,0)に設定されている場合。

関連する問題