Skip to content

Instantly share code, notes, and snippets.

@dutran90
dutran90 / UITableView.txt
Last active August 30, 2015 04:52
UITableVIew
#pragma mark - UITableView Datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"ClubCell";
ClubCell *cell = (ClubCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
@dutran90
dutran90 / CocoaPods
Last active August 19, 2016 14:57
CocoaPods
1) Open terminal
2) $ sudo gem install cocoapods (gem will get installed in Ruby inside System library)
3)pod setup
4) create a xcode project
5) cd "$ path to your project root directory" (cd /Volumes/...)
6) pod init
7) open -a Xcode Podfile (podfile will get open in text mode. Initially it will be emppty put the follwoing line of code.)
8) pod 'AFNetworking', '0.9.1' (It’s finally time to add your first dependency using CocoaPods! Copy and paste the following into your pod file, right after target "AFNetworkingProject" do:)
9) pod install
Make sure you run “$ pod install” command every time you add or delete a new library to the Podfile.
@dutran90
dutran90 / AFNetworking
Last active December 23, 2015 12:52
AFNetworking
//GET
+(void) checkLoginWithUsername:(NSString*)username andPassword:(NSString*)password InBackground:(void(^)(BOOL success)) completionHandler{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *para = [NSDictionary dictionaryWithObjectsAndKeys:username, @"email", password, @"password", nil];
[manager setRequestSerializer:[AFHTTPRequestSerializer serializer]];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"admin" password:@"admin"];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
[manager GET:@"http://lottofy.gleblu.com/ws/login.php" parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([[responseObject objectForKey:@"success"] doubleValue] == 0) {
completionHandler(NO);
@dutran90
dutran90 / AppDelegate
Created August 18, 2015 15:38
AppDelegate
// Call ViewController with UINavigationController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
MainVC *vcMain = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vcMain];
self.window.rootViewController = nav;
nav.navigationBarHidden = YES;
return YES;
@dutran90
dutran90 / MBHUDProgress
Created August 18, 2015 15:42
MBHUDProgress
// BASIC
MBProgressHUD *hud;
hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = @"loading...";
[hud show:YES];
--> [hud hide:YES];
@dutran90
dutran90 / UICollectionView
Created August 18, 2015 15:49
UICollectionView
#pragma mark - Process data
- (CGFloat) calculateWidthItem{
return ([[UIScreen mainScreen]bounds].size.width -16 - 4*10)/2;
}
- (CGFloat) calculateHeightItem{
return (([[UIScreen mainScreen]bounds].size.width -16 - 4*10)/2)*1.5;
}
--> widthItem = [self calculateWidthItem];
heightItem = [self calculateHeightItem];
@dutran90
dutran90 / Design Pattern
Created August 18, 2015 16:05
Design Pattern
// SINGLETON PATTERN
-->.h:
+ (instancetype)sharedInstance;
-->.m:
+ (instancetype)sharedInstance
{
static MyClass *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[MyClass alloc] init];
@dutran90
dutran90 / Autolayout Programming
Created August 18, 2015 16:11
Autolayout Programming
// Width constraint, half of parent view width
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:centerView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeWidth
multiplier:0.5
constant:0]];
// Height constraint, half of parent view height
@dutran90
dutran90 / Show&Hide Keyboard
Last active August 27, 2015 15:07
Show&Hide Keyboard
//ViewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
@dutran90
dutran90 / MyTextField.h
Created August 27, 2015 15:23
MyTextFiled padding
#import <UIKit/UIKit.h>
@interface MyTextField : UITextField
{
BOOL isEnablePadding;
float paddingLeft;
float paddingRight;
float paddingTop;
float paddingBottom;
}