hit counter

Timeline

My development logbook

NSNotification and View Controller

I have created a number of custom UIViewControllers for UICollectionViewCell programmatically (Apple makes it really easy to create good looking GUI. AutoLayout is not as bad as I heard from the blogsphere. But I digress).

Now I want to be able to have these UIViewController to subscribe to an adhoc NSNotification. I have ensured that there is no typo in the my notification name (The name is defined in a header file). I have also make sure the notification is fired on the main thread, like so:

dispatch_async(dispatch_get_main_queue(),^{
    [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_NAME object:self];
});

However my UIViewControllers still do not receive any notification at all.

It turns out it is because the controllers instances have gone out of scope. I found out by putting a NSLog in the dealloc method. It proves that the controllers have gone out of scope.

In order to keep them around in memory, I added a NSMutableDictionary to keep reference to these controllers. Will test if it has any adverse effect or not.

Capture Part of Ios Screen as Image

1
2
3
4
UIGraphicsBeginImageContext(theCell.bounds.size);
[theCell.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *renderedCellImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

source

Land Tax Is Adjustable

if Land Tax Adjustable is checked, it means the vendor seeks reimbursement of land tax from the buyer

Conda Update

At first I am confused by this conda output. It seems suggest conda is going to upgrade python even though there is no new version of python.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$ conda update python
Updating conda environment at /Users/antkong/anaconda

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    conda-3.0.4                |           py27_0         103 KB
    openssl-1.0.1c             |                0         2.1 MB
    python-2.7.6               |                1         9.9 MB
    readline-6.2               |                2         275 KB

The following packages will be UN-linked:

    package                    |            build
    ---------------------------|-----------------
    conda-2.2.7                |           py27_0
    python-2.7.6               |                0
    readline-6.2               |                1

The following packages will be linked:

    package                    |            build
    ---------------------------|-----------------
    conda-3.0.4                |           py27_0   hard-link
    openssl-1.0.1c             |                0   hard-link
    python-2.7.6               |                1   hard-link
    readline-6.2               |                2   hard-link

Proceed ([y]/n)?

It turns out they are the dependency of conda, which will be upgraded from 2.2.7 to 3.0.4

Changing NSTimeZone

To convert a NSDate into another Timezone

1
2
3
4
5
6
7
8
    NSCalendarUnit val = NSCalendarUnitYear|NSCalendarUnitHour;
    NSCalendar* dupCal =  [[NSCalendar currentCalendar] copy];

    [dupCal setTimeZone:toTimeZone]; // setting to a different timezone
    NSDateComponents *dupComponents = [dupCal components:val fromDate:[NSDate date]];

    // print out the time and check
    NSLog(@"%ld", (long)[dupComponents hour]);