2
協議的方法,當所需的協議的方法還沒有被實施的Xcode只是給予警告更好的解決方案來處理要求沒有實現
Warning: method 'xxx' in protocol 'xxx' not implemented
我有一個自定義視圖就像UITableView
誰擁有一個dataSource
屬性。爲了確保數據源是不爲零,是該方法迴應我這樣做
NSAssert(self.dataSource != nil, @"menu's dataSource shouldn't be nil");
if ([self.dataSource respondsToSelector:@selector(menu:numberOfRowsInColumn:)]) {
return [self.dataSource menu:self
numberOfRowsInColumn:self.currentSelectedMenudIndex];
} else {
NSAssert(0 == 1, @"required method of dataSource protocol should be implemented");
return 0;
}
我不知道是否有處理所需的方法的缺失更優雅的方式?
任何想法?
哈哈,好一個〜 – dopcn 2014-10-29 06:07:16