我想添加一個子視圖按鈕單擊。但是當點擊按鈕時,視圖不會出現。iOS addSubview不顯示視圖
下面是點擊按鈕的很乾脆代碼:
-(IBAction) dimChangeBtnClick: (id) sender
{
[self addSubview:myHelloWorldViewController.view];
}
myHelloWorldViewController是HelloWorldViewController類的一個實例。
HelloWorldViewController.h:
#import <UIKit/UIKit.h>
@interface HelloWorldViewController : UIViewController
-(IBAction)showMessage;
@end
和HelloWorldViewController.m:
#import <Foundation/Foundation.h>
#import "HelloWorldViewController.h"
@implementation HelloWorldViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
-(IBAction)showMessage
{
UIAlertView *hellowWorldAlert = [[UIAlertView alloc] initWithTitle:@"My First App" message:@"Hello, World!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[hellowWorldAlert show];
}
@end
我想表明的觀點是 HelloWorldViewController.xib
是否有在objective-之間需要一些額外的鏈接c代碼和.xib文件,除了命名它們相同嗎?從我的大二問題可以明顯看出,我對iOS很新,所以任何建議都將不勝感激。請告訴我是否有任何我遺漏的關鍵信息。
謝謝!這些資源非常有用,絕對有我需要的信息。 –