2011年6月5日 星期日

ManagedObjectContext

先在該view controller定義一個
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext; 


在<ClassName>AppDelegate.m 中的 - (BOOL)application:didFinishLaunchingWithOptions: 把managedObjectContext帶給viewController的managedObjectContext。如此一來在可以view controller就可以用了。

    rootViewController.managedObjectContext = context;

找出是哪一個Context

    Cost *costEvnet = (Cost *)[NSEntityDescription insertNewObjectForEntityForName:@"Cost" inManagedObjectContext:self.managedObjectContext];
    
設定內容
    [costEvnet setType:@"Food"];
    [costEvnet setMoney:[NSNumber numberWithInt:200]];
    [costEvnet setCostDate:[NSDate date]];
    
存檔
    NSError *error = nil;
    if (![self.managedObjectContext save:&error]) {
        NSLog(@"RootViewController save Failed.");
    }

建立要求
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:entityDescription];

執行要求並回傳到Array中
    NSError *error = nil;
    NSMutableArray *objects = [[self.managedObjectContext executeFetchRequest:request error:&error] mutableCopy];

刪除記錄

        NSManagedObject *eventToDelete = [ self.contextMutableArray objectAtIndex:indexPath.row];
        [self.managedObjectContext deleteObject:eventToDelete];

Custom Table View Cell

  • Command+N: Cocoa Touch -> Object-C class -> UITableViewCell -> [ClassName]
  • Command+N: User Interface -> Empty -> [ClassNameForNib]
  • 可以在ClassNameForNib裡面排版這個Cell要怎麼表示。並連結ClassName裡的IBOutlet


修改 ViewController的  - (UITableViewCell *)tableView: cellForRowAtIndexPath:

    static NSString *CustomCellIdentifier = @"CustomCellIdentifier";
    
    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];
    if (cell == nil) {
        NSLog(@"cell == nil");
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        
        for (id oneObject in nib) {
            if ([oneObject isKindOfClass:[CustomCell class]]) {
                cell = (CustomCell *)oneObject;
                break;
            }
        }

    }


這是因為再還沒有可再利用的顯示格時,他會先從nib載入。以上的nib會回傳一個這個nib內所有的物件陣列。由於Apple並無標準文件告知會由何種順序出現,而且也一直再改變,不得已只好先依此來找到Cell的表示方式。

若有改變到高度的話,就要修改


- (CGFloat)tableView:heightForRowAtIndexPath: 

Navigation Controller

  • 加入 UINavigation 的 instance variable
  • - (BOOL)application: didFinishLaunchingWithOptions: 這個Function中 把要加入的root controller放進來。
  • 放進來要在alloc viewController時要以自己的class命名
  • 最後使用 window addsubview的方式。
  • 可以用self.navigationItem的方式加入button


2011年2月6日 星期日

Stanford iphone Lecture 6 in 2010 Fall

生命週期...
想不到才第六節課~
怎麼有很多東西的感覺XD
這節課主要在Demo~所以東西比較少,但很實用。



2011年2月5日 星期六

Stanford iphone Lecture 5 in 2010 Fall

終於前進到第五章了!
邊看影片邊做筆記真的是超級慢的!
不過我相信這是必要的!

加油!

這次要講的是Protocol,看起來挺重要的。


2011年1月23日 星期日

Stanford iphone Lecture 4 in 2010 Fall

這次主要要講基本的Type~
講元素就能更快進入狀況了。

本來已經紀錄了一些了,但是太多、太雜!
覺得這些東西都是用到就會查的東西。
最後決定只把重要的記一記。

當中會有學生提問問題:我一律把他放到最上面好了!
因為我想這將是會有盲點的解答。

Here we GO!

2011年1月22日 星期六

Stanford iphone Lecture 3 in 2010 Fall

這集開始講解Object-C的Method表示,和一些基本的Type。
我想跟C++一樣,開始要進入重點了。
我總是覺得,一種語言的重點就在於他是如何表示的。
整個表示式又各自代表什麼意思。
這才是重要的!
一旦搞懂,接下來就很好理解了。

讓我搞懂你吧!!!!

2011年1月16日 星期日

Stanford iphone Lecture 2 in 2010 Fall

開始介紹Object的基本語法了。總算有個開端了!
但這集他有介紹個例子,我就不在這邊贅述了。
我直接紀錄相關注意事項就好。

2011年1月2日 星期日

Stanford iphone Lecture 1 in 2010 Fall

距離上次寫note已經兩個月了...我想這就是BLOG個意義吧XD
可以知道上次寫的是什麼時候...
不過沒有辦法動手寫,只能看,真的是一個很讓人手癢的事情@@
不要看我可以過得好一點XD
現在有弄到了一個可以編譯的環境了,所以可以動手做了!於是我又開始看上課內容了!
希望這次可以不懈一點.....
以下這些筆記都是觀看來自於Standford on iTunes的上課講義和來自IPA程序員的熱心人轉的翻譯影音檔。謝謝你們讓我比較好瞭解。