2009-02-24 32 views

Trả lời

2

Có thể loại được. Chỉ cần tạo một khung nhìn mới bằng cách sử dụng một bộ điều khiển khung nhìn và tạo một thể hiện của khung nhìn đó trong lớp của bạn. Sau đó, trong một ibaction bạn có thể làm một số loại bỏ và thêm subviews. Đó chỉ là một cách tho nhanh chóng và dễ dàng, bạn có thể nhận được vào chi tiết nhiều hơn với cách bạn sẽ quản lý từng xem vv

Chỉnh sửa theo yêu cầu: Trong lớp học của bạn, bạn sẽ tạo ra một thể hiện của nó trong giao diện như sau:

MyClass *myClass; (make sure to alloc and init in the init or awakeFromNib method) 

sau đó thực hiện một thể hiện của các đại biểu ứng dụng trong IBAction như thế này:

MyAppDelegate *myAppDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 

Và sau đó bạn có thể làm điều này để chuyển đổi từ một quan điểm khác:

[self removeFromSuperView]; (or self.view in case this is a view controller) 
[[myAppDelegate window] addSubview:myClass]; 
+0

nhờ cho câu trả lời ur. u có thể cho tôi một số ví dụ hoặc mã mẫu? – Nasir

1

Bạn có thể làm một cái gì đó như sau để thêm một cái nhìn programatically:

 //If you create controllers via XCode, just link them in the .h file with IBOutlet 
    UIViewController *aViewController = [[UIViewController alloc] initWithNibName:@"YourNibName" bundle:[NSBundle mainBundle]]; 
    self.viewController = aViewController; 
    [aViewController release]; 
    // Add the view controller's view as a subview of the window 
    UIView *controllersView = [viewController view]; 
    [window addSubview:controllersView]; 
    [window makeKeyAndVisible]; 
Các vấn đề liên quan