之間協調我是相當新的iOS開發,我不能夠環繞一個概念我的頭..怎樣的UIViewController和UIView的
我有兩個UIViewController
類 - ViewController
和SecondViewController
。最初,文件的ViewController
類被加載,其中僅包含UIButton
。當點擊此按鈕時,SecondViewController
開始起作用,它需要加載由我的UIView
類創建的視圖,該類名爲ViewClass
。 ViewClass
只包含一個UIButton
。
單擊ViewController xib上的按鈕,我所得到的只是一個黑屏,我不明白爲什麼loadView和viewDidLoad方法會被調用很多次。(輸出如下所示)!
這裏是我的代碼..
ViewController.m
@implementation ViewController
@synthesize secondViewController = _secondViewController;
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self)
{
NSLog(@"init of ViewController called");
self.secondViewController = [[SecondViewController alloc] init];
}
return self;
}
- (IBAction)buttonPressed:(id)sender {
[self presentViewController:self.secondViewController animated:YES completion:NULL];
NSLog(@"presented");
}
SecondViewController.m
-(void)loadView
{
NSLog(@"loadView Called");
self.myView = [[ViewClass alloc] init];
[self.view addSubview:self.myView];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
NSLog(@"init of SVC called");
}
return self;
}
-(void)viewWillAppear:(BOOL)animated
{
NSLog(@"view WIll appear called");
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"view did load called");
}
ViewClass.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(@"init OF View Called");
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.titleLabel.text = @"Heyy";
[self addSubview:button];
}
return self;
}
,這就是我得到的控制檯..
2013-10-04 11:03:08.454 MVCPractice1[30957:a0b] Cannot find executable for CFBundle 0xa894b30 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/AccessibilityBundles/CertUIFramework.axbundle> (not loaded)
2013-10-04 11:03:08.503 MVCPractice1[30957:a0b] init of ViewController called
2013-10-04 11:03:08.504 MVCPractice1[30957:a0b] init of SVC called
2013-10-04 11:03:09.773 MVCPractice1[30957:a0b] loadView Called
2013-10-04 11:03:09.774 MVCPractice1[30957:a0b] init OF View Called
2013-10-04 11:03:09.775 MVCPractice1[30957:a0b] view did load called
2013-10-04 11:03:09.776 MVCPractice1[30957:a0b] loadView Called
2013-10-04 11:03:09.777 MVCPractice1[30957:a0b] init OF View Called
2013-10-04 11:03:09.778 MVCPractice1[30957:a0b] view did load called
2013-10-04 11:03:09.779 MVCPractice1[30957:a0b] loadView Called
2013-10-04 11:03:09.779 MVCPractice1[30957:a0b] init OF View Called
2013-10-04 11:03:09.780 MVCPractice1[30957:a0b] view did load called
2013-10-04 11:03:09.781 MVCPractice1[30957:a0b] loadView Called
2013-10-04 11:03:09.781 MVCPractice1[30957:a0b] init OF View Called
2013-10-04 11:03:09.782 MVCPractice1[30957:a0b] view did load called
2013-10-04 11:03:09.783 MVCPractice1[30957:a0b] view WIll appear called
2013-10-04 11:03:09.783 MVCPractice1[30957:a0b] loadView Called
2013-10-04 11:03:09.784 MVCPractice1[30957:a0b] init OF View Called
2013-10-04 11:03:09.785 MVCPractice1[30957:a0b] view did load called
2013-10-04 11:03:09.785 MVCPractice1[30957:a0b] loadView Called
2013-10-04 11:03:09.786 MVCPractice1[30957:a0b] init OF View Called
2013-10-04 11:03:09.787 MVCPractice1[30957:a0b] view did load called
2013-10-04 11:03:09.787 MVCPractice1[30957:a0b] presented
行..我..但我仍不能看到我添加的viewClass類的按鈕。我仍然得到一個空白的黑色屏幕 – Shradha