1. Trang chủ
  2. » Công Nghệ Thông Tin

CÁCH xử DỤNG FILE XIB TRONG OBJECTIVE c

10 406 1

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Nội dung

CÁCH XỬ DỤNG FILE XIB TRONG OBJECTIVE C Trong hướng dẫn hướng dẫn bạn tạo file xib thiết kế giao diện điều khiển hình … file xib gì? file xib file thiết kế giao diện người dùng Chứa cảnh game hình phần mềm Khác MainStoryboard gồm tất hình liên kết giao diện trực quan liên kết Tuy dự án lớn dẫn đến liên kết nhìn rối mắt , khó quản lý luồng Lúc file Xib phát huy tác dụng dễ quản lý luồng Hơn bạn máy yếu load MainStoryboard phải load tất hình hay bị lác file xib ta gọi file file gọi Chúng ta thiết kế nào! Chúng ta load file xib ,Ta xoá file MainStoryboard Tạo file xib mới.New file lựa chọn vẽ!Ta tạo file xib lưu ý đặt tên file tý gọi theo tên file Như ta tạo file xib thành công ! Thiết kế giao diện nào: Kéo vào label để hiển thị ,và nút button để bắt kiện Để bắt kiện giới thiệu phía Đây có giao diện nhiên chưa thể chạy Do chưa đăng ký class quản lý View Và chưa đăng ký xem file Xib này!!! Ok! click vào File’s Owner : xuất ô kết nối class hình bên sau chọn tên class quản lý, xcode tự động kết nối: Kết nối ViewController để quản lý file Xib phải chuột vào File’s Owner, kéo View vào hình vừa tạo ra! Kết nối View với hình Xib Ok kết nối thành công giao diện !!!Tiếp theo đăng ký load file Xib ứng dụng khởi chạy! Vào file AppDelegate.m thêm đoạn mã sau!!! #import "tên View controller vừa tạo để quản lý hình thiết kế.h" Ở đây: #import "ViewController.h" đoạn mã giải thích cụ thể!Cách đăng ký hình khởi động nào!Và kết nối Navigation nào! - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // dang ky fullScreen self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // dang ky viewcontroller nao mac dinh la file xib Viewcontroller!!! //uiViewcontroller quan ly man hinh nao UIViewController *controller=[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; // đăng ký gốc navigation nam tren viewcontroller UINavigationController *navigation=[[UINavigationController alloc] initWithRootViewController:controller]; // dang ky man hinh dau tien cua window self.window.rootViewController=navigation;// bạn truyền trược tiếp controller vào navigation! 11 // cho phep hien thi dau tien 12 [self.window makeKeyWindow]; 13 return YES; 10 14 } Trước biên dịch ta vào grneral chọn launchScreen! cho file launchScreen! chạy để giới thiệu xong đến file xib.!! Biên dịch chạy thử!!! Ta kết sau! Tiếp theo cần thêm ViewController khác !!! điều hướng chúng! ánh xạ label sang class quản lý chúng label để phân biệt xem hình @property (weak, nonatomic) IBOutlet UILabel *labelXib; Thêm biến đếm để phân biệt hình xib hiển thị lên label! @property (nonatomic, assign)int number; Thêm đoạn mã sau để settext cho label ! - (void)viewDidLoad { [super viewDidLoad]; self.labelXib.text=[[NSString alloc] initWithFormat:@"this is Xib %d",self.number]; } Ánh xạ action cho nút touch up inside:và thêm đoạn mã sau! - (IBAction)touchUpInside:(id)sender { ViewController *controller=[[ViewController alloc] init]; controller.number=self.number+1; [self.navigationController pushViewController:controller animated:YES]; } Tạo ViewController ViewController tăng biến đếm lên cuối dùng push để hiển thị Viewcontroller vào!… Tuy nhiên Khi không muốn back lại muốn full hình ta dùng phương pháp presentViewControler!!! - (IBAction)prsent:(id)sender { ViewController *controller=[[ViewController alloc] init]; controller.number=self.number+1; [self presentViewController:controller animated:YES completion:nil]; }

Ngày đăng: 19/10/2016, 00:44

TỪ KHÓA LIÊN QUAN

w