1

私はiosプログラミングが初めてで、エラーが発生しています。私のアプリは雑誌用で、UIScrollView を使用して記事を表示します。

私のアプリでは、ジェスチャーを使用して2つのボタンを使用してUIScrollViewをナビゲートする2つの方法があります.最初のページか最後のページかを評価し、場合に応じてボタンを無効にする場合。

このメソッドでビューに初めてアクセスしたときはすべて問題ありませんが、2 回目のアクセスではボタンが失敗しますが、ジェスチャーは正常に動作します。ボタンまたはジェスチャーからメソッドを呼び出すときに違いはありますか?

コードは次のとおりです。

//Here is where I assign the method to the buttons and gesture
[articuloAnterior addTarget:self action:@selector(cambiarPaginaAnterior) forControlEvents:UIControlEventTouchUpInside];

[articuloSiguiente addTarget:self action:@selector(cambiarPaginaSiguiente) forControlEvents:UIControlEventTouchUpInside];

UISwipeGestureRecognizer *avanzarPagina = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(cambiarPaginaSiguiente)];
avanzarPagina.direction = UISwipeGestureRecognizerDirectionLeft;

UISwipeGestureRecognizer *regresaPagina = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(cambiarPaginaAnterior)];
regresaPagina.direction = UISwipeGestureRecognizerDirectionRight;

//Here are the functions
-(void)cambiarPaginaAnterior{
//This method checks if it is the first page, in case it isn't it go one page back
NSLog(@"Pagina actual %d de %d",paginaMostrada,[appDelegate.seccionActual.listadoArticulos count]-1);
if (0 != paginaActual) {
    paginaMostrada = paginaActual - 1;
    NSLog(@"Pagina actual %d de %d",paginaMostrada,[appDelegate.seccionActual.listadoArticulos count]-1);
    [self cambiarLimites];
  }
}

-(void)cambiarPaginaSiguiente{
//In this method I check the actual page (paginaActual) to see if it is the last one, if it isn't then it go forward
NSInteger limiteDePaginacion = [appDelegate.seccionActual.listadoArticulos count] - 1;
 NSLog(@"Pagina actual %d de %d",paginaMostrada,limiteDePaginacion);
if (limiteDePaginacion != paginaActual) {
    paginaMostrada = paginaActual + 1;
    NSLog(@"Pagina actual %d de %d",paginaMostrada,limiteDePaginacion);
    [self cambiarLimites];
  }
}

-(void)cambiarLimites{
//Here i save the point where the user was located and save it in an array
NSValue *posicionActualDeLaVista = [NSValue valueWithCGPoint:CGPointMake(0, contenedorGeneral.contentOffset.y)];
[posicionDeLaPagina removeObjectAtIndex:paginaActual];
[posicionDeLaPagina insertObject:posicionActualDeLaVista atIndex:paginaActual];

//Here I change the value of the actual page
paginaActual=paginaMostrada;

//Here I disable the buttons or make them able
if (paginaActual==([appDelegate.seccionActual.listadoArticulos count]-1)) {
    articuloSiguiente.enabled = NO;
}
else {
    articuloSiguiente.enabled = YES;
}
if (paginaActual==0) {
    articuloAnterior.enabled = NO;
}
else {
    articuloAnterior.enabled = YES;
}

//A log to check the state of the buttons
NSLog(@"Pagina actual %d estado del boton anterior %@, estado del boton siguiente %@",paginaActual,articuloAnterior.enabled?@"yes":@"no",articuloSiguiente.enabled?@"yes":@"no");

//Acces an array with the points the user where
CGPoint puntoDeVisualizacion = [[posicionDeLaPagina objectAtIndex:paginaActual]CGPointValue];

//Here I remove the content of the uiscrollview and put the new one
[vistaTemporale removeFromSuperview];
vistaTemporale = [vistasParaElScroll objectAtIndex:paginaActual];
vistaTemporale = [self ResizeDeLaVista:vistaTemporale laPagina:paginaActual];
[contenedorGeneral addSubview:vistaTemporale];
[contenedorGeneral setContentOffset:puntoDeVisualizacion animated:NO];

//Check the view height and change the UIScrollView content height
float limitanteDeAltura;
limitanteDeAltura = [[appDelegate.viewSizes objectAtIndex:paginaActual]floatValue];
[contenedorGeneral setContentSize:CGSizeMake(anchoDeVista, limitanteDeAltura)];
}

斜めスクロールを無効にする必要があるため、独自のジェスチャを作成したため、一度に 1 つのビューのみを表示することをお勧めしますが、ジェスチャは失敗したものではなく、ボタンが無効にならず、で宣言されています.h ファイルと最初のアクセスでは正常に動作しますが、なぜ失敗するのですか?

4

1 に答える 1

0

助けてくれてありがとう、問題はツールバーにボタンを追加していたことと、メモリ管理エラーのためにボタンがまだそこにあるため、新しいボタンは無効になっていますが、古いボタンは表示されアクティブになっています。

于 2012-05-31T18:58:41.103 に答える