2010-09-21 199 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]; 
} 

編碼快樂...

相關問題