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

HƯỚNG dẫn sử DỤNG TABLEVIEW TRONG IOS

13 292 0

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

HƯỚNG DẪN SỬ DỤNG TABLEVIEW TRONG IOS với việc tạo ứng dụng hello World nắm bắt message bắt kiện button kết nối file làm việc với tableView ios tableView thiết kế nhiều ios List Bài hát, list ăn, setting ios… hướng dẫn cụ thể cho bạn tableView! nào! ! ! bước 1- CREATE PROJECT MỚI -vào Main.storyboard -kéo vào tableView bắt đầu -Kéo vào tableviewcell -kéo vào imageView label contenView -table quản lý cell -> cell chứa contenView tương tác trực tiếp với conTenView -table có hàm tạo sẵn AppDelegate khuôn mẫu để quản lý hứng kiên bắt data lên contenView – Để làm điều kết nối Appdelegate -thực nối tableView với viewcontroller uỷ quyền cho ViewController quản lý tableView qua :UITableViewDelegate,UITableViewDataSource – ta tạo giao diện xong : -ta xoá ViewController.h m tạo file tableViewController.h m create file: sau chọn thư mục lưu ok! -Kết nối tableViewController với viewcontroller nó! class tableViewController quản lý viewcontroller mà tạo tạo identifine: để xác định xem làm cho section nào! vào tableViewController.h kết nối : @interface tableViewController : UIViewController khởi tạo class quản lý Cell tableView sau kéo nôí image label @interface cellitem: UITableViewCell @property(weak ,nonatomic) IBOutlet UILabel *label; @property (weak ,nonatomic) IBOutlet UIImageView* imageIcon; @end -Quản lý tableView: AppDelegate có hàm bắt buộc // đưa số lượng hàng nhóm section quản lý khuôn mẫu cell -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ }; //Hứng data vào cell tương tác liệu -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ } – Chúng ta phải khởi tạo liệu đưa vào cell… cho ảnh vào resource đặt tên @interface tableViewController () @property(nonatomic,strong) NSArray *item;//text @property(nonatomic,strong) NSArray *linkUrl;/tên ảnh+ đôi @end viewdidload khởi tạo giá trị - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view self.item=@[@"Na",@"Ổi",@"Táo"]; self.linkUrl=@[@"na.jpg",@"oi.jpg",@"tao.jpg" } (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ return [self.item count]; //đưa số lượng cột }-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ cellitem *cell=[tableView dequeueReusableCellWithIdentifier:@"cellitem" forIndexPath:indexPath];//khởi tạo indentifine cell.label.text=self.item[indexPath.row];// lấy text đưa vào cell.imageIcon.image=[UIImage imageNamed:self.linkUrl[indexPath.row]];/lấy tên ảnh đưa vào return cell; 10 } ok !!! phần giúp bạn tương tác với row section tablewView! link full mã nguồn! http://www.mediafire.com/download/hmvyip19pdqbhsr/tableViewController.zip [...]... khuôn mẫu cell -(NSInteger )tableView: (UITableView * )tableView numberOfRowsInSection:(NSInteger)section{ }; //Hứng data vào cell tương tác dữ liệu -(UITableViewCell * )tableView: (UITableView * )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ } – Chúng ta phải khởi tạo dữ liệu đưa vào cell… cho ảnh vào resource đặt tên @interface tableViewController () @property(nonatomic,strong) NSArray *item;//text... @interface tableViewController : UIViewController khởi tạo class quản lý Cell trong tableView sau đó kéo nôí image và label 1 @interface cellitem: UITableViewCell 2 @property(weak ,nonatomic) IBOutlet UILabel *label; 3 @property (weak ,nonatomic) IBOutlet UIImageView* imageIcon; 4 @end -Quản lý tableView: AppDelegate có 2 hàm bắt buộc // đưa ra số lượng hàng trong. .. @property(nonatomic,strong) NSArray *item;//text @property(nonatomic,strong) NSArray *linkUrl;/tên ảnh+ đôi @end trong viewdidload khởi tạo giá trị 1 - (void)viewDidLoad { 2 3 4 5 [super viewDidLoad]; // Do any additional setup after loading the view self.item=@[@"Na",@"Ổi",@"Táo"]; self.linkUrl=@[@"na.jpg",@"oi.jpg",@"tao.jpg" 6 } 1 (UITableViewCell * )tableView: (UITableView * )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{... * )tableView: (UITableView * )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 2 3 return [self.item count]; //đưa ra số lượng cột 4 }-(UITableViewCell * )tableView: (UITableView * )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 5 cellitem *cell= [tableView dequeueReusableCellWithIdentifier:@"cellitem" forIndexPath:indexPath];//khởi tạo indentifine 6 cell.label.text=self.item[indexPath.row];//... imageNamed:self.linkUrl[indexPath.row]];/lấy tên ảnh đưa vào 8 return cell; 9 10 } ok !!! phần tiếp theo mình sẽ giúp các bạn tương tác với row và section trong tablewView! link full mã nguồn! 1 http://www.mediafire.com/download/hmvyip19pdqbhsr/tableViewController.zip

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

Xem thêm: HƯỚNG dẫn sử DỤNG TABLEVIEW TRONG IOS

TỪ KHÓA LIÊN QUAN

w