嘿,我是新手在ios開發。我想展開和摺疊的tableview,所以我做它的代碼是:展開和摺疊桌面單元格
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section != 0)
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSDictionary *d=[self.arForTable objectAtIndex:indexPath.row];
if([d valueForKey:@"Objects"]) {
NSArray *ar=[d valueForKey:@"Objects"];
BOOL isAlreadyInserted=NO;
for(NSDictionary *dInner in ar){
NSInteger index=[self.arForTable indexOfObjectIdenticalTo:dInner];
isAlreadyInserted=(index>0 && index!=NSIntegerMax);
if(isAlreadyInserted) break;
}
if(isAlreadyInserted) {
[self miniMizeThisRows:ar];
} else {
NSUInteger count=indexPath.row+1;
NSMutableArray *arCells=[NSMutableArray array];
for(NSDictionary *dInner in ar)
{
[arCells addObject:[NSIndexPath indexPathForRow:count inSection:1]];
[self.arForTable insertObject:dInner atIndex:count++];
}
[tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationTop];
}
}
}
和我的最小化等作爲
-(void)miniMizeThisRows:(NSArray*)ar{
for(NSDictionary *dInner in ar) {
NSUInteger indexToRemove=[self.arForTable indexOfObjectIdenticalTo:dInner];
NSArray *arInner=[dInner valueForKey:@"Objects"];
if(arInner && [arInner count]>0){
[self miniMizeThisRows:arInner];
}
if([self.arForTable indexOfObjectIdenticalTo:dInner]!=NSNotFound) {
[self.arForTable removeObjectIdenticalTo:dInner];
[self.tblLeft deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexToRemove inSection:1]]withRowAnimation:UITableViewRowAnimationBottom];
}
}
}
從這個方法和編碼我實現了Expand and Collapse
tableViewCell,該工程排方法。由於它在單擊時展開tableViewCell並在第二次單擊Expandable單元時將其摺疊。
但我想這樣工作:點擊任何可展開的單元格,其他可展開的單元格將自動崩潰。
任何人都可以幫助我嗎?
在此先感謝。