2010-09-21 200 views
0

我有这样的问题......我对apps..when基于我按在第二screen..it按钮导航工作显示了一个新的观点从一个视图到另一个视图

button=[[UIButton alloc]initWithFrame:frame]; 
button.frame = CGRectMake(60,250,200,69); 
[button setTitle:@"Crack Now" forState:UIControlStateNormal]; 
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
button.opaque; 
[self.view addSubview:button]; 

-(void)buttonClicked{ 
    secondViewcontroller=[[SecondViewController alloc]initWithNibName:@"secondViewController" bundle:[NSBundle mainBundle]]; 
    [self.navigationController pushViewController:secondViewcontroller animated:YES]; 
    [self.navigationController presentModalViewController:secondViewcontroller animated:YES]; 
} 

-(void)viewDidLoad{ 

    CGRect frame=CGRectMake(80,0,200,100); 
    label=[[UILabel alloc] initWithFrame:frame]; 
    label.text = @"text"; 
    label.backgroundColor = [UIColor clearColor]; 
    label.textColor = [UIColor blueColor]; 
    label.textAlignment = UITextAlignmentLeft; 
    label.font = [UIFont systemFontOfSize:20]; 
    [self.view addSubview:label]; 
    myImage=[[UIImageView alloc]initWithFrame:frame]; 
    myImage.frame=CGRectMake(90,70,150,170); 
    [myImage setImage:[UIImage imageNamed:@"Untitled-3.jpg"]]; 
    myImage.opaque; 
    [self.view addSubview:myImage]; 

    [super viewDidLoad];    
} 

回答

1

我真的不明白你问这里有什么,但我可以看到一点毛病的youre代码:

[self.navigationController pushViewController:secondViewcontroller animated:YES]; 
[self.navigationController presentModalViewController:secondViewcontroller animated:YES]; 

您应该只使用其中的一个..

推视图控制器意味着新的视图将被推到接收者的(s elf.navigationcontroller)堆栈。换句话说,它会推入一个新的视图,导航栏将显示一个后退按钮到最后一个视图。

目前的模态视图控制器意味着它将呈现给定视图控制器管理的模式视图给用户(self.navigationController)。模式视图没有后退按钮。你必须调用[self dismissModalViewController];再次移除它。

编辑: 你也应该释放secondViewController后推或呈现模态,释放内存.. [secondViewController release];

0

而我所看到的是每当你点击按钮你的应用程序会崩溃。因为您的方法

[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 

必须是 COLON不能在那里。正如你所定义的方法,无需任何发件人作为参数

[button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside]; 

和其余被告知如上

-(void)buttonClicked{ 
    secondViewcontroller=[[SecondViewController alloc]initWithNibName:@"secondViewController" bundle:[NSBundle mainBundle]]; 
    [self.navigationController pushViewController:secondViewcontroller animated:YES]; 
// [self.navigationController presentModalViewController:secondViewcontroller animated:YES]; 
    [secondViewcontroller release]; 
} 

编码快乐...

相关问题