繁体   English   中英

为什么从uibutton而不是从手势调用时方法失败?

[英]Why method fail when called from uibutton but not from a gesture?

我是ios编程的新手,但我遇到了错误。 我的应用程序是用于杂志,并且我使用UIScrollView来查看文章。

在我的应用程序中,我有两种使用手势和2个按钮在UIScrollView中导航的方法,因为我根据页面更改了滚动视图的内容,并使用一种前进和后退的方法,在其中使用了一种是否评估是第一页还是最后一页,并根据情况禁用按钮。

第一次使用此方法访问视图时,一切都很好,但是第二次访问时,按钮失败,但手势正常,从按钮或手势调用方法时有区别吗?

这是代码:

//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)];
}

我做出了自己的手势,因为我需要取消对角线滚动,所以我认为一次只显示一个视图是一个好主意,但是手势并不是一个失败,按钮没有被禁用,它们被声明为.h文件,并且在首次访问时它们可以正常工作,知道它们为什么会失败吗?

感谢您的帮助,但问题是我在工具栏中添加了按钮,并且由于内存管理错误,按钮仍在此处,因此新按钮处于禁用状态,而旧按钮处于可见和活动状态,对此问题表示抱歉

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM