UIScrollView,按钮单击不起作用...

时间:2011-07-30 09:00:02

标签: iphone scrollview

我正在使用iOS Developer Library中的示例代码PageControl。

我想做的是

1)在MyView.xib中添加一个按钮  2)如果单击该按钮,请转到第2页

所以,这就是我所做的。

1)在MyView.xib中创建了一个按钮 2)在“MyViewController.m”中创建IBAction,如

 - (IBAction)toPageTwo:(id)sender;

    {

        NSLog(@"button clicked...");
        PhoneContentController * callSview = [[PhoneContentController alloc] init];
        [callSview showPage:2];

    }

然后,在PhoneContentController.m中创建以下方法转到第二页。

- (void)showPage:(int)page;

{

    [scrollView setContentOffset:CGPointMake(320*(page -1), 0) animated:YES];    
    NSLog(@"Method called..and the scrollview width is %f  ", scrollView.frame.size.width);
    //prints negative value or 0.000. why?

}

问题

[scrollView setContentOffset:CGPointMake(320*(page -1), 0) animated:YES];    
如果单击按钮,则

不起作用。 (如果在PhoneContentController.m中调用showPage,它工作正常)

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我认为:

- (IBAction)toPageTwo:(id)sender;
{
   NSLog(@"button clicked...");
   PhoneContentController * callSview = [[PhoneContentController alloc] init];
   [callSview showPage:2];

您无需分配新的PhoneContentController,因为您已经在主PhoneContentController。只需将showPage消息发送至self

即可
- (IBAction)toPageTwo:(id)sender;
{
   NSLog(@"button clicked...");
   [self showPage:2];

这只是一个猜测,因为我不知道你的方法究竟属于哪个类(但我猜它是PhoneContentController)。