gpt4 book ai didi

iphone - 使用缩进级别在 ios 中的 UITableview 中下拉

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:17:59 24 4
gpt4 key购买 nike

这里我想要一个多级 TableView 。 I was able to create it successfully but when one of the levels is selected, any previously expanded dropdown level should collapse.我使用了下面的示例代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"cellid"];
if (cell==nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellid"] autorelease];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell.textLabel setText:[[arrtable objectAtIndex:indexPath.row] objectForKey:@"name"]];
[cell setIndentationLevel:[[[arrtable objectAtIndex:indexPath.row] objectForKey:@"level"] intValue]];

return cell;
}

什么时候选中行

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"arrtable :%@",arrtable);


NSDictionary *d=[arrtable objectAtIndex:indexPath.row];
NSLog(@"d%@",d);
if([d valueForKey:@"objects"]) {

NSArray *ar=[d valueForKey:@"objects"];

BOOL isAlreadyInserted=NO;

for(NSDictionary *dInner in ar ){
NSInteger index=[arrtable 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:0]];
[arrtable insertObject:dInner atIndex:count++];
}
[tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft];
}
}
}

- (void)miniMizeThisRows:(NSArray*)ar{
for(NSDictionary *dInner in ar ) {
NSUInteger indexToRemove=[arrtable indexOfObjectIdenticalTo:dInner];
NSArray *arInner=[dInner valueForKey:@"objects"];
if(arInner && [arInner count]>0){
[self miniMizeThisRows:arInner];
}
if([arrtable indexOfObjectIdenticalTo:dInner]!=NSNotFound) {
[arrtable removeObjectIdenticalTo:dInner];
[testtable deleteRowsAtIndexPaths:[NSArray arrayWithObject:
[NSIndexPath indexPathForRow:indexToRemove inSection:0]
]
withRowAnimation:UITableViewRowAnimationRight];
}
}
}

这里我有一个示例图片: Only I need to select one of the options

最佳答案

好吧,我所能做的就是为您提供一个链接,您可以从那里下载该示例代码,我希望它能帮助您完成此任务 TableView Link .

TreeView Tableview

tree Graph

Tree control

Coca Tree Example

关于iphone - 使用缩进级别在 ios 中的 UITableview 中下拉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16565706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com