2013-06-27 15 views
0

基本上我有類的主要功能是充當tableView委託的對象。在objective-c中沒有多重繼承的情況下,最優雅的方法是什麼?

我想補充一些超類。當然,只有一個超類,我想要靈活性。如果後者我想將此功能隨意添加到其他類中,怎麼辦?

基本上這些都用於處理表格,用戶可以刪除或重新排列行代碼等

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    NSAssert(false, @"Should be called at child View"); 
    return nil; 
} 



-(Class) classBookmarked 
{ 
    assert(false); 
    return nil; 
} 


-(void) setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [self.delegate.tvDelegated setEditing:editing animated:animated]; 

    if (!editing) 
    { 
     NSArray * newIds = _arManagedObjectArray.convertArrayOfNSManagedObjectToItsDefaultSelector; 

     [self varManagedObjectArrayUpdated]; 
     [BGBookmarkStorer vReportBookmarkStatusToServer:newIds Flag:@"update" withClass:self.classBookmarked]; 
    } 
} 


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSUInteger row = indexPath.row; 
    [self deleteARow:row]; 

} 

-(void)deleteARow:(NSUInteger) row 
{ 
    NSIndexPath * indexPath = [NSIndexPath indexPathForRow:row inSection:0]; 
    [_arManagedObjectArray removeObjectAtIndex:row]; 
    [self.delegate.tvDelegated deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    [self varManagedObjectArrayUpdated]; 
} 

-(void) varManagedObjectArrayUpdated 
{ 
    [self.bookmarkStorer vUpdateBookMarkIDwithArray:_arManagedObjectArray]; 
    [self.delegate vUpdateNumberOfStuffs]; 

} 

-(BGBookmarkStorerForPlacesandCatalog *) bookmarkStorer 
{ 
    assert(false); 
    return nil; 
} 

- (NSArray*) theBookmarkedIDs 
{ 
    return self.bookmarkStorer.bookmarkedIDs; 

} 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath 
{ 
    NSMutableArray * mutableBusinessBookmarked= _arManagedObjectArray; 
    NSManagedObject *bizOrCatToMove = mutableBusinessBookmarked[sourceIndexPath.row]; 
    [mutableBusinessBookmarked removeObjectAtIndex:sourceIndexPath.row]; 
    [mutableBusinessBookmarked insertObject:bizOrCatToMove atIndex:destinationIndexPath.row]; 
    //_arManagedObjectArray=mutableBusinessBookmarked; 
    [self varManagedObjectArrayUpdated]; 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return UITableViewCellEditingStyleDelete; 
} 
+0

我不明白你的意思是'我想把它添加到一些超類.' –

回答

2

創建的UITableViewController的子類。在那裏實現你所有的功能。將它用作所有視圖控制器的超類。

+0

超類很好。但是objective-c不允許多重繼承,我想要更靈活的東西。 –

1

如果我理解正確,你需要一個實用的地方,你可以把代碼和重用在你的表視圖控制器,對不對? 如果是這樣,只需在UITableViewController上創建一個類別並將代碼放在那裏;-)

+0

類別不是很靈活。我正在考慮作文。但是,那麼委託人必須明確地調用我想重複的代碼的委託。 –

相關問題