SlideShare a Scribd company logo
1 of 34
Lậptrìnhứngdụng iPhone Truong QuocPhu  <phutq8014@setacinq.com.vn> SETA:CINQ Vietnam, Ltd - 3D Building, Nguyen Phong Sac Str, CauGiay Dist, Ha Noi
Nội dung chính Môitrườnglậptrìnhứngdụngiphone Ngônngữ Objective-c iPhone SDK Build & Distribute app trên device ,[object Object],[object Object]
Objectiv-C Là ngôn ngữ hướng đối tượng, Cùng họ với c/c++ , nhưng syntax khác với c/c++ Classname.h @interfaceclassname: superclassname {  // instance variables  (type_1) proprety1; 	(type_2) proprety1; }  + classMethod1;  + (return_type)classMethod2; br />+ (return_type)classMethod3:(param1_type)param1_varName;  -(return_type)instanceMethod1:(param1_type)param1_varName:(param2_type)param2_varName;  -(return_type_object*)instanceMethod2WithParameter:(param1_type_object*)param1_varName andOtherParameter:(param2_type)param2_varName;  @end Classname.m #import “Classname.h “ @implementation classname @synthesize proprety1; (id)hello {  printf("Recipient says hello!");  return self;  } ,[object Object],[object Object]
Objectiv-C(3): Reference Counting Every object has a retain count  Defined on NSObject  As long as retain count is > 0, object is alive and valid +allocand -copy create objects with retain count == 1 -retain increments retain count -release decrements retain count When retain count reaches 0, object is destroyed -deallocmethod invoked automatically One-way street, once you’re in -dealloc there’s no turning back
Objectiv-C: Foundation Framework Foundation FW: là FW phát triển trên objective-c. Cung cấp tất cả các lớp cơ bản : string, number, collection, file , Tasks, timers, threads , File system, pipes, I/O, bundles NSObject Là lớp root Quản lý về bộ nhớ: init, dealloc
Objectiv-C: các kiểu dữ liệu cơ bản NSString:  NSString *aString =  @”Hello World!”; NSString *log = [NSStringstringWithFormat: @”It’s ‘%@’”, aString]; 	NSLog(@”%@”,log); - (NSString *)stringByAppendingString:(NSString *)string; - (NSString *)stringByAppendingFormat:(NSString *)string; - (NSString *)stringByDeletingPathComponent;  - (BOOL)isEqualToString:(NSString *)string; - (BOOL)hasPrefix:(NSString *)string; - (int)intValue; - (double)doubleValue
Objectiv-C: các kiểu dữ liệu cơ bản(2) NSArray: + arrayWithObjects:(id)firstObj, ...;   - (unsigned)count; - (id)objectAtIndex:(unsigned)index; -(unsigned)indexOfObject:(id)object; NSMutableArray; NSMutableArray: subclasses NSArray  + (NSMutableArray *)array; - (void)addObject:(id)object; - (void)removeObject:(id)object; - (void)removeAllObjects; - (void)insertObject:(id)object atIndex:(unsigned)index;
NSDictionary:  là kiểu dữ liệu quản lý Object theo key + dictionaryWithObjectsAndKeys: (id)firstObject, ...; - (unsigned)count; - (id)objectForKey:(id)key; ,[object Object],+ (NSMutableDictionary *)dictionary; - (void)setObject:(id)object forKey:(id)key; - (void)removeObjectForKey:(id)key; - (void)removeAllObjects; Objectiv-C: các kiểu dữ liệu cơ bản(3)
Objectiv-C: các kiểu dữ liệu cơ bản(4) NSNumber: Trong objective-c có thể dụng các kiểu dữ liệu  số cơ bản trong C: int, float, double. NSNumber là kiểu dữ liệu số ở dạng object + (NSNumber *)numberWithInt:(int)value; + (NSNumber *)numberWithDouble:(double)value; - (int)intValue; - (double)doubleValue; NSData / NSMutableData  Arbitrary sets of bytes NSDate / NSCalendarDate Times and dates http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC
iPhone SDK Xcode
Views UIView 1 hình khoảng vuông trên màn hình Nội dung được hiển thị trên đó Bắt các sự kiện  1 view có một superview 1 view không có hoặc có nhiều subview - (void)addSubview:(UIView *)view; - (void)removeFromSuperview; - (void)insertSubview:(UIView *)view atIndex:(int)index; - (void)insertSubview:(UIView *)view belowSubview:(UIView *)view; - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)view;
Views (2) • CGPoint: { x , y } • CGSize:  { width , height } • CGRect:  { origin , size }
Views : Create view Interface Builder 2 1 4 3
Views : Create view Sử dụng code CGRect frame = CGRectMake(0, 0, 200, 150); UIView *myView = [[UIViewalloc] initWithFrame:frame]; 		[window addSubview:myView]; [myViewrelease];
View: các loại view cơ bản 1. UILable 2.UIImageView 3.UITextField 4. UISlider 5.UISegmentedControl 6.UISwitch 7.UIButton 2 3 1 4 5 6 7
ViewController UIViewController: root class Các loại Viewcontroller: UITabbarController UINavigationController UITableViewController
ViewController:UITabbarController Là Array các viewcontroller Tabbar: điều hướng các viewcontroller
ViewController:UINavigationController Là stack các viewcontroller Navigation bar Push to add a view controller - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; Pop to remove a view controller - (void)popViewControllerAnimated:(BOOL)animated;
UITabBarController+ UINavigationController
UITableView Hiện thị dữ liệu dạng bảng Xử lý điều hướng các chức năng chương trình
UITableView (plain style)
UITableView (Group style)
UITableViewDataSource Số lượng section trong table -(NSInteger)numberOfSectionsInTableView:(UITableView *)table Số cell trong 1 section - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; Hiện thị nội dung Cell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; NSIndexPath: section , row
UITableView Delegate Xử lý các sự kiện trên table: click cell, sửa cell, xóa cell - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
UITableViewController Khi tạo UITableViewController sẽ tạo luông UITableview và kết hợp UITableViewDataSource và UITableView Delegate vào nội dung.
Data  Property Lists SQLite Core Data
Sqlite Là kiểu database nhỏ, nhẹ thường được dùng trong các ứng dụng nhỏ, không cần sever.  Cấu trúc truy vấn theo chuẩn của sql Quản lý file sqlite: add-on firefox SQLite Manager Khi sử dụng thêm thư viện libsqlite3.dylib
sqlite Open Database intsqlite3_open(const char *filename, sqlite3 **db); Query DB sqlite3_stmt *statement;	 sqlite3_prepare_v2(db,[sqlStringUTF8String],-1,&statement,nil); while (sqlite3_step(statement) == SQLITE_ROW) { int a =sqlite3_column_int(statement, 0);   //with number 	nsstring *b =  [NSString stringWithUTF8String:(char *)					sqlite3_column_text(statement, 1);	//with string } sqlite3_finalize(statement); Close DB sqlite3_close(db);
Build & Distribute Cótàikhoảntrênhttps://developer.apple.com/
Iphone programming
Iphone programming

More Related Content

Similar to Iphone programming

BÀI 7 Làm việc với thành phần mới và phạm vi ứng dụng của HTML5 - Giáo trình FPT
BÀI 7 Làm việc với thành phần mới và phạm vi ứng dụng của HTML5 - Giáo trình FPTBÀI 7 Làm việc với thành phần mới và phạm vi ứng dụng của HTML5 - Giáo trình FPT
BÀI 7 Làm việc với thành phần mới và phạm vi ứng dụng của HTML5 - Giáo trình FPTMasterCode.vn
 
Thêm sửa-xóa-combobox - c#
Thêm sửa-xóa-combobox - c#Thêm sửa-xóa-combobox - c#
Thêm sửa-xóa-combobox - c#Văn Dũng
 
MVC
MVCMVC
MVCtkot
 
OOP_02_Java can ban.pdf
OOP_02_Java can ban.pdfOOP_02_Java can ban.pdf
OOP_02_Java can ban.pdfssuserd01a5c
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#Hihi Hung
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#LanLT2011
 
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]leduyk11
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#LanLT2011
 
OOP in Java - Ver1.1
OOP in Java -  Ver1.1OOP in Java -  Ver1.1
OOP in Java - Ver1.1vdlinh08
 
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cậnTrần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cậnSecurity Bootcamp
 
Khóa học lập trình ios
Khóa học lập trình iosKhóa học lập trình ios
Khóa học lập trình iosĐào tạo Seo
 

Similar to Iphone programming (20)

Bai08 10 java_fx
Bai08 10 java_fxBai08 10 java_fx
Bai08 10 java_fx
 
BÀI 7 Làm việc với thành phần mới và phạm vi ứng dụng của HTML5 - Giáo trình FPT
BÀI 7 Làm việc với thành phần mới và phạm vi ứng dụng của HTML5 - Giáo trình FPTBÀI 7 Làm việc với thành phần mới và phạm vi ứng dụng của HTML5 - Giáo trình FPT
BÀI 7 Làm việc với thành phần mới và phạm vi ứng dụng của HTML5 - Giáo trình FPT
 
Thêm sửa-xóa-combobox - c#
Thêm sửa-xóa-combobox - c#Thêm sửa-xóa-combobox - c#
Thêm sửa-xóa-combobox - c#
 
MVC
MVCMVC
MVC
 
Bai tap thuc hanh
Bai tap thuc hanhBai tap thuc hanh
Bai tap thuc hanh
 
OOP_02_Java can ban.pdf
OOP_02_Java can ban.pdfOOP_02_Java can ban.pdf
OOP_02_Java can ban.pdf
 
Flutter vs React Native 2018
Flutter vs React Native 2018Flutter vs React Native 2018
Flutter vs React Native 2018
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#
 
C# cơ bản hay
C# cơ bản hayC# cơ bản hay
C# cơ bản hay
 
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#
 
OOP in Java - Ver1.1
OOP in Java -  Ver1.1OOP in Java -  Ver1.1
OOP in Java - Ver1.1
 
Yii
YiiYii
Yii
 
005. LAP TRINH C#.pdf
005. LAP TRINH C#.pdf005. LAP TRINH C#.pdf
005. LAP TRINH C#.pdf
 
005. LAP TRINH C#.pdf
005. LAP TRINH C#.pdf005. LAP TRINH C#.pdf
005. LAP TRINH C#.pdf
 
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cậnTrần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cận
 
Khóa học lập trình ios
Khóa học lập trình iosKhóa học lập trình ios
Khóa học lập trình ios
 
Ch06
Ch06Ch06
Ch06
 

Iphone programming

  • 1. Lậptrìnhứngdụng iPhone Truong QuocPhu <phutq8014@setacinq.com.vn> SETA:CINQ Vietnam, Ltd - 3D Building, Nguyen Phong Sac Str, CauGiay Dist, Ha Noi
  • 2.
  • 3.
  • 4. Objectiv-C(3): Reference Counting Every object has a retain count Defined on NSObject As long as retain count is > 0, object is alive and valid +allocand -copy create objects with retain count == 1 -retain increments retain count -release decrements retain count When retain count reaches 0, object is destroyed -deallocmethod invoked automatically One-way street, once you’re in -dealloc there’s no turning back
  • 5. Objectiv-C: Foundation Framework Foundation FW: là FW phát triển trên objective-c. Cung cấp tất cả các lớp cơ bản : string, number, collection, file , Tasks, timers, threads , File system, pipes, I/O, bundles NSObject Là lớp root Quản lý về bộ nhớ: init, dealloc
  • 6. Objectiv-C: các kiểu dữ liệu cơ bản NSString: NSString *aString = @”Hello World!”; NSString *log = [NSStringstringWithFormat: @”It’s ‘%@’”, aString]; NSLog(@”%@”,log); - (NSString *)stringByAppendingString:(NSString *)string; - (NSString *)stringByAppendingFormat:(NSString *)string; - (NSString *)stringByDeletingPathComponent; - (BOOL)isEqualToString:(NSString *)string; - (BOOL)hasPrefix:(NSString *)string; - (int)intValue; - (double)doubleValue
  • 7. Objectiv-C: các kiểu dữ liệu cơ bản(2) NSArray: + arrayWithObjects:(id)firstObj, ...; - (unsigned)count; - (id)objectAtIndex:(unsigned)index; -(unsigned)indexOfObject:(id)object; NSMutableArray; NSMutableArray: subclasses NSArray + (NSMutableArray *)array; - (void)addObject:(id)object; - (void)removeObject:(id)object; - (void)removeAllObjects; - (void)insertObject:(id)object atIndex:(unsigned)index;
  • 8.
  • 9. Objectiv-C: các kiểu dữ liệu cơ bản(4) NSNumber: Trong objective-c có thể dụng các kiểu dữ liệu số cơ bản trong C: int, float, double. NSNumber là kiểu dữ liệu số ở dạng object + (NSNumber *)numberWithInt:(int)value; + (NSNumber *)numberWithDouble:(double)value; - (int)intValue; - (double)doubleValue; NSData / NSMutableData Arbitrary sets of bytes NSDate / NSCalendarDate Times and dates http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC
  • 11.
  • 12. Views UIView 1 hình khoảng vuông trên màn hình Nội dung được hiển thị trên đó Bắt các sự kiện 1 view có một superview 1 view không có hoặc có nhiều subview - (void)addSubview:(UIView *)view; - (void)removeFromSuperview; - (void)insertSubview:(UIView *)view atIndex:(int)index; - (void)insertSubview:(UIView *)view belowSubview:(UIView *)view; - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)view;
  • 13. Views (2) • CGPoint: { x , y } • CGSize: { width , height } • CGRect: { origin , size }
  • 14.
  • 15.
  • 16. Views : Create view Interface Builder 2 1 4 3
  • 17. Views : Create view Sử dụng code CGRect frame = CGRectMake(0, 0, 200, 150); UIView *myView = [[UIViewalloc] initWithFrame:frame]; [window addSubview:myView]; [myViewrelease];
  • 18. View: các loại view cơ bản 1. UILable 2.UIImageView 3.UITextField 4. UISlider 5.UISegmentedControl 6.UISwitch 7.UIButton 2 3 1 4 5 6 7
  • 19. ViewController UIViewController: root class Các loại Viewcontroller: UITabbarController UINavigationController UITableViewController
  • 20. ViewController:UITabbarController Là Array các viewcontroller Tabbar: điều hướng các viewcontroller
  • 21. ViewController:UINavigationController Là stack các viewcontroller Navigation bar Push to add a view controller - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; Pop to remove a view controller - (void)popViewControllerAnimated:(BOOL)animated;
  • 23. UITableView Hiện thị dữ liệu dạng bảng Xử lý điều hướng các chức năng chương trình
  • 26. UITableViewDataSource Số lượng section trong table -(NSInteger)numberOfSectionsInTableView:(UITableView *)table Số cell trong 1 section - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; Hiện thị nội dung Cell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; NSIndexPath: section , row
  • 27. UITableView Delegate Xử lý các sự kiện trên table: click cell, sửa cell, xóa cell - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
  • 28. UITableViewController Khi tạo UITableViewController sẽ tạo luông UITableview và kết hợp UITableViewDataSource và UITableView Delegate vào nội dung.
  • 29. Data Property Lists SQLite Core Data
  • 30. Sqlite Là kiểu database nhỏ, nhẹ thường được dùng trong các ứng dụng nhỏ, không cần sever. Cấu trúc truy vấn theo chuẩn của sql Quản lý file sqlite: add-on firefox SQLite Manager Khi sử dụng thêm thư viện libsqlite3.dylib
  • 31. sqlite Open Database intsqlite3_open(const char *filename, sqlite3 **db); Query DB sqlite3_stmt *statement; sqlite3_prepare_v2(db,[sqlStringUTF8String],-1,&statement,nil); while (sqlite3_step(statement) == SQLITE_ROW) { int a =sqlite3_column_int(statement, 0); //with number nsstring *b = [NSString stringWithUTF8String:(char *) sqlite3_column_text(statement, 1); //with string } sqlite3_finalize(statement); Close DB sqlite3_close(db);
  • 32. Build & Distribute Cótàikhoảntrênhttps://developer.apple.com/