English 中文(简体)
A. 紧迫时的意见交换
原标题:Switching views when pressing button
  • 时间:2011-11-06 00:35:25
  •  标签:
  • iphone
  • ios

I am trying to load a new view when I click a button in the app. The error I am getting is -

View Switcher[6867:207] -[UIView pushViewController:animated:]: unrecognized selector sent to instance 0x6010660

and the source code snippet is -

-(IBAction) blueButtonPressed:(id)sender{

if(self.yellowViewController == nil){
    YellowViewController *yellowController = [[YellowViewController alloc] initWithNibName:@"YellowView" bundle:nil];
    self.yellowViewController = yellowController;
    //[yellowController release];

    //[self.view addSubview:yellowController.view];
//[self.view pushViewController:self.yellowViewController];
    [self.navigationController pushViewController:self.yellowViewController];
[yellowController release];
}
//[self.navigationController pushViewController:self.yellowViewController animated:YES];
}

我使用的是头号档案——

#import <UIKit/UIKit.h>

@class BlueViewController;
@class YellowViewController;


@interface BlueViewController : UIViewController {  
YellowViewController *yellowViewController;
BlueViewController *blueViewController; 
}
-(IBAction)blueButtonPressed:(id)sender;

@property(retain) YellowViewController *yellowViewController;
@property(retain, nonatomic) BlueViewController *blueViewController;
@end

与Xcode项目的联系是:

最佳回答

pushViewController is a UINavigationController method.

[self.navigationController pushViewController:self.yellowViewController animated:YES];

I m assuming you are in a UIViewController subclass


您能否担任Xcode项目一,需要看到这一点。


Ok, I ve look into your code, the problem is that you don t have any navigationController. Your app is structured like a view base application not like a navigation base application.
The result is that your self.navigationController == nil, that is why that call is ignored.

在您的申请书中,您需要一些照样的法典。

UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:switchViewController];
navCon.navigationBarHidden = YES;
self.window.rootViewController = navCon;
[window makeKeyAndVisible];

申请表......


In your code, when you click on your switch in the toolbar, it s "working" because your using this code :

[blueViewController.view removeFromSuperview];
[self.view insertSubview:yellowViewController.view atIndex:0];

没有航行 在这一进程中,主计长。

问题回答

You should use [self.view addSubview:yellowController.view];

最好有导航控制器,由您推向或从中抽出乘客。

UIView does not have pushViewController:animated: as a method.

You can push only in UINavigationController





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签