开发者

going from one view to another view

i have a problem in that...i am working on navigation based apps..when i press a button in second screen..it shows a new view

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=[[开发者_StackOverflow社区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];            
}


I dont really understand what you are asking here, but i can see one thing wrong with youre code:

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

You should only use one of these..

Push view controller means that the new view will be pushed onto the reciever's (self.navigationcontroller) stack. In other words it will push in a new view and the navigation bar will display a back button to youre last view.

Present modal view controller means that it will present a modal view managed by the given view controller to the user (self.navigationController). A modal view does not have a back button. You have to call [self dismissModalViewController]; to remove it again.

Edit: You should also release secondViewController after pushing or presenting modal, to free up memory.. [secondViewController release];


And What I am seeing is whenever you click the button your application is gonna crash. Because your method

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

must be COLON must not be there. as you have defined the method without any sender as argument

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

and remaining is told as above

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

hAPPY cODING...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜