Thursday, February 28, 2013

Communication Between MVC Controllers

When there are more than two MVC controllers, controllers need to pass data or send notifications between two controllers. For example, a table list controller, parent, may push to an item edit controller, child, when an item is selected. The easiest way to is to set a property in child controller and pass the reference to parent controller to child's property. However, this strategy has one drawback: strong binding between parent and child controllers. In case the parent controller is changed to another kind of controller, the property of child has to be updated.

The alternative way is to implement delegate in Objective-C. Define a delegate in .h, then keep communication by defined methods in the delegate. Here is the steps of this strategy.

Define a Delegate

The delegate provides APIs to pass data or to send notifications. For example, the following codes define a update method:

@protocol MyEntityEditDelegate <NSObject>

- (void) updateEntity:(NSIndexPath *)index;

@end

Add a Delegate Property in Parent Controller

The next step is to implement the delegate property in the parent controller. This breaks the strong binding between the parent and child. The child will call parent by the delegate APIs.


@interface ParentListViewController :
    UITableViewController <..., MyEntityEditDelegate>

....
@end

Define a Delegate Property in Child Controller

The last step is to add delegate property in the child controller. This will let the child hold a reference to its parent by delegate.

@interface ChildEntityEditViewController : ...

@property (nonatomic, weak) id<MyEntityEditDelegate> delegate;

@end

Notice that the property type is id<...> type. This prevents the coupling between the parent and child.

Read More...

Monday, February 18, 2013

What is the Next Big Thing for Apple

This is a question most people ask today. There are many rumors about iWatch, a wearable device can be attached to human body. Personally, I think this is a tip of iceberg, and it must be a part of Apple eco-system.

In the past, from Apple's WWDC seminars, I noticed that Apple has been very interested in BLE (Bluetooth Low Energy) technology. There was a demo about using iPod touch as a BLE device to communicate with iPhone. This is a open standard protocol and has great application potential in many areas.

I remembered one Video of Steve Jobs' talking about what Apple learned from its past. Apple invested a lot in personal computer, OO technology and graphics OS. Steve was so fascinated with this. This came out of the result of Mac computer. One thing Steve mentioned that he missed out network and internet, the potential products in this area. Actually, from Apple's past, the company has invested a lots in this area with innovative technology, such as zero configuration networking or Bonjour.

With iPhone's success, I think this has been raised to top priority of Apple's next technology innovation. iWatch is just one device for motion monitor device (MMD). It seems that Apple is also working on motion event device (MED) as well.

The next big thing is built from the past technology or concept in Apple for long time. When it is out, I think it will be a big surprise WOW for consumers. This will be not just one single device. This is a whole system with iPhone and mobile devices. The innovation will be built on a solid system and it will an open system for developers.

Read More...

Sunday, February 10, 2013

Update my Codes to iOS 6

After I updated my Xcode to 4.6, I got several compiling errors when I tried to compile my app. It seems that they are iOS 6 related.  Most of them are easy to fix. However, I had a little bit hard time to nail down two.

The first one is block related. I used self within block. In Xcode 4.6, this is a potential memory issue: Capturing 'self' strongly in this block is likely to lead to a retain cycle. With the help of SO, I quickly found the solution: using __weak prefix to capture self as none-retaining variable. Then use the var in the block.

if (entity.imagePath) {
   __weak UITableViewController *weakSelf = self;
   // Load image from entity to doc helper with handler
   [self.docHelper addImageDocs:myDoc
            withCompleteHandler:^{
                [weakSelf.tableView reloadRowsAtIndexPaths:
                   aPath
                   withRowAnimation:UITableViewRowAnimationBottom];
            }];
}

The second one was tough for me, because it is Storyboard related. The warning only indicates a potential issue but I could not locate it: table view background color is deprecated in ios 6.0. In a similar way, I got an answer from SO. But in my case, I have too many views and components. It is hard to locate the issue. Eventually, I found a way to view the storyboard as XML text and soon I located the deprecated color. I submitted my answer to SO.

References

Read More...

Friday, February 01, 2013

Start Weight Lost Program

I t has been two weeks after my vacation from China. I read a news from Melaleuca about weight lost program. Basically, the program works in a simple way: reduce daily large meals into small ones, meal size like my fist. Take GC Attain or Attain between meals to replace snack food. Exercise 45 minutes daily, and take a Access bar before walk out. Optional: take PfoFlex20 within one hour after exercise.

Today I sent my application to Melaleuca. Here are my numbers:


  • Weight: 74Kg
  • Belt waist: 94 cm
  • Height: 1.72m

I also took a photo before I start the plan today. I'll see if I'll loss 10% after the ten week plan.

Reference


Read More...