2012-03-01 70 views
0

在這3行代碼中,有這個「委託」,我無法在代碼中的其他任何地方找到它,即使不在FruitsAppDelegate中。我不記得它是什麼意思:這是一個慣例嗎?它會自動代表AppDelegate嗎?委託在uiapplication sharedApplication:convention?

// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    FruitAppDelegate *appDelegate = (FruitAppDelegate*)[[UIApplication sharedApplication] delegate]; 
    return appDelegate.fruits.count; 
} 

感謝

回答

0

UIApplication定義了必須採取UIApplicationDelegate協議並實施一些協議方法的委託。每個應用程序都必須有一個委託。 在你的情況下,它是FruitAppDelegate。

+0

感謝,但具體是:[[[UIApplication sharedApplication]委託]'「委託」字是應用程序自動識別爲委託權? – Paul 2012-03-01 08:45:33

+0

是的。委派在您創建項目時自動設置。所以「委託」屬性只是指向你的FruitAppDeleagte。 – nagan 2012-03-01 09:04:39

+0

好的謝謝你的幫助 – Paul 2012-03-01 09:12:21