我有一個應用程序,它具有從我的主視圖通過一些定製的UIButtons導航到的許多視圖。主視圖命名爲iBMRViewController,並以通過界面構建器放入的PNG圖像形式提供了一些歡迎圖形。它還具有6個自定義UIButtons,我通過使用以下代碼創建了它們;使用一個IBAction切換回主視圖控制器
// This is the code which creates, and defines the properties of the 'Warning' button on the main view.
UIButton *warningButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
warningButton.frame = CGRectMake(225.0, 270.0, 60.0, 60.0);
[warningButton setTitle:@"" forState:UIControlStateNormal];
warningButton.backgroundColor = [UIColor clearColor];
[warningButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal ];
UIImage *warningButtonImageNormal = [UIImage imageNamed:@"Warning.png"];
UIImage *warningStretchableButtonImageNormal = [warningButtonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[warningButton setBackgroundImage:warningStretchableButtonImageNormal forState:UIControlStateNormal];
UIImage *warningButtonImagePressed = [UIImage imageNamed:@"whiteButton.png"];
UIImage *warningStretchableButtonImagePressed = [warningButtonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[warningButton setBackgroundImage:warningStretchableButtonImagePressed forState:UIControlStateHighlighted];
[warningButton addTarget:self action:@selector(warningButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:warningButton];
現在,這一切工作正常,按鈕功能完美,顯然我也有行動爲他們設置完美的工作。在每一頁上,我都有一個UINavigationBar和一個UINavigationItem,通過界面構建器進行設置,並設置爲使用下面的代碼將我帶回到主視圖;
//This is the code which opens up the new view when 'Begin' button is tapped.
-(IBAction)beginHomeButtonAction:(id)sender {
iBMRViewController *controller = [[BeginView alloc] initWithNibName:@"iBMRViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
這也適用,但是,當它把我帶回到了「iBMRViewController」它只顯示什麼通過Interface Builder的XIB文件(即歡迎PNG文件)成立。它不顯示我通過代碼添加的按鈕。
任何人都可以告訴我哪裏出了問題嗎?將不勝感激。
感謝
謝謝。我會盡力理解你剛纔說的笑話。當我明白他在說什麼時,谷歌確實是我的朋友。但這個術語對我來說都是比較新的,所以有時很難。我想我對你在說什麼有所瞭解,所以我會試一試。謝謝 – 2011-04-05 10:41:05
沒錯。如有疑問,請在您的原始問題中張貼介紹子視圖的代碼。 – mvds 2011-04-05 10:44:06
我設法解決這個問題,而不是在我的IBAction中使用這段代碼 - iBMRViewController * controller = [[BeginView alloc] initWithNibName:@「iBMRViewController」bundle:nil]; - 我將[[BeginView alloc]更改爲[[iBMRViewController alloc]),它就像一個魅力。 – 2011-04-06 14:56:01