Skip to content

Instantly share code, notes, and snippets.

View jenhausu's full-sized avatar

Will Su jenhausu

View GitHub Profile
@jenhausu
jenhausu / UIAlertViewDelegate.m
Last active August 29, 2015 14:08
Local Notification
<UIAlertViewDelegate>
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
NSTimeInterval postponTime;
[[[LocalNotification alloc] init] setLocalNotificationWithMessage:self.localNotification.alertBody
fireDate:[NSDate dateWithTimeInterval:postponTime sinceDate:self.localNotification.fireDate]
@jenhausu
jenhausu / NSObjCRuntime.h
Created November 2, 2014 02:49
int vs. NSInteger vs. NSNumber
#ifndef _OBJC_NSOBJCRUNTIME_H_
#define _OBJC_NSOBJCRUNTIME_H_
#include <TargetConditionals.h>
#include <objc/objc.h>
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
@jenhausu
jenhausu / NSCalendar.m
Last active August 29, 2015 14:09
時間相關
NSCalendar *usersCalendar = [[NSLocale currentLocale] objectForKey:NSLocaleCalendar];
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; //NSCalendarIdentifierGregorian
@jenhausu
jenhausu / 刪除資料.m
Last active August 29, 2015 14:10
CoreData
[self.managedObjectContext deleteObject:fetchDataArray[indexPath.row]];
[self.managedObjectContext save:nil];
fetchDataArray = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil]; //reload data
- dateByAddingTimeInterval:
@jenhausu
jenhausu / 刪除.php
Last active August 29, 2015 14:11
網頁程式(新增、刪除、查詢、更新)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> Delete </title>
</head>
<body>
<a href = "./index.html"> Home </a>
<a href = "./create.html"> Create </a>
<a href = "./read.php"> Read </a>
@jenhausu
jenhausu / 使用.h
Last active August 29, 2015 14:11
Protocol
@interface RootTableViewController : UITableViewController <delegation1, delegation2>
...
@end
@jenhausu
jenhausu / 0_reuse_code.js
Last active August 29, 2015 14:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jenhausu
jenhausu / 介紹
Last active August 29, 2015 14:12
UINavigationController
關於UIWindow、UINavigationController和UITabBarController我把他們都理解成一個容器,並不用於真正顯示內容,它們之前可以嵌套比如這樣::
UIWindow > UITabBarController > UINavigationController > UIViewController真正顯示內容的是UIViewController
1. UIWindow 如果是一個Chrome瀏覽器的窗口,那麼其他幾個可以這樣理解
2. UITabBarController 是Chrome的Tab欄
3. UINavigationController 是Chrome的歷史記錄功能
4. UIViewController 是Chrome顯示網頁區域
一個Chrome窗口可以有多個Tab, Tab下只有一個顯示網頁的區域,因為保存有歷史記錄,所以可以在之前打開的頁面間切換
@jenhausu
jenhausu / 1.m
Last active January 1, 2017 13:54
偵測當返回鍵被按下時
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if ([self.navigationController.viewControllers indexOfObject:self] == NSNotFound) {
// back button was pressed. We know this is true because self is no longer in the navigation stack.
NSLog(@"[self.navigationController.viewControllers indexOfObject:self] == NSNotFound");
}
}