ios - 如何使用objective-c用两个NSMutableArray填充可扩展的TableView
<p><p>我正在使用 <a href="https://github.com/wannabegeek/ExpandableTableView" rel="noreferrer noopener nofollow">Expandable UITableview</a>由 Tom Fewster 创建。我想使用两个 <code>NSMutableArray</code> 来调整示例,这是一个场景,如果有人想要从 webservice json 数据填充可扩展/折叠 TreeView 表,则需要实现。因此,由于在他的示例中 <code>GroupCell</code> 没有数组,我想知道我该怎么做?请记住,我的 Objective-C 仍然生锈,所以我要问这个问题。</p>
<p>我的尝试只显示组的第一个 ObjectAtIndex:indexPath:0。</p>
<p>我希望能够填充表格并获得这样的输出;</p>
<ul>
<li>A组
<ul>
<li>第 1a 行</li>
<li>第 2a 行</li>
<li>第 3a 行</li>
</ul></li>
<li>B 组
<ul>
<li>第 1b 行</li>
<li>第 2b 行</li>
</ul></li>
<li>C组
<ul>
<li>第 1c 行</li>
<li>第 2c 行 </li>
<li>第 3c 行
等等。</li>
</ul></li>
</ul>
<p>如果您以这种方式更好地理解它,您也可以使用 JSON 数据来解释您的答案。</p>
<p>在这里我想用 JSON 数据填充表格,以便 GroupCell 显示 class_name 和 rowCell 显示 subject_name。这是我从 JSON Web 服务解析的控制台;</p>
<pre><code>(
{
"class_id" = 70;
"class_name" = Kano;
subject = (
"subject_id" = 159;
"subject_name" = "Kano Class";
}
);
},
{
"alarm_cnt" = 0;
"class_id" = 71;
"class_name" = Lagos;
subject = (
"subject_id" = 160;
"subject_name" = "Lagos Class";
}
);
},
{
"alarm_cnt" = 3;
"class_id" = 73;
"class_name" = Nasarawa;
subject = (
"subject_id" = 208;
"subject_name" = "DOMA Class";
},
"subject_id" = 207;
"subject_name" = "EGGON Class";
},
"subject_id" = 206;
"subject_name" = "KARU Class";
},
"subject_id" = 209;
"subject_name" = "LAFIA Class";
},
"subject_id" = 161;
"subject_name" = "Nasarawa State Class";
}
);
},
{
"alarm_cnt" = 2;
"class_id" = 72;
"class_name" = Rivers;
subject = (
"subject_id" = 162;
"subject_name" = "Rivers Class";
}
);
}
</code></pre>
<p>)</p>
<p>我试过了,这是我的片段</p>
<pre><code>- (UITableViewCell *)tableView:(ExpandableTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
</code></pre>
<p>{
静态 NSString *CellIdentifier = @"RowCell";</p>
<pre><code>UITableViewCell *cell = ;
NSDictionary *d= ;
NSArray *arr=;
NSDictionary *subitems = ;
NSLog(@"Subitems: %@", subitems);
NSString *siteName = ;
cell.textLabel.text =siteName;
//}
NSLog(@"Row Cell: %@", cell.textLabel.text);
// just change the cells background color to indicate group separation
cell.backgroundView = [ initWithFrame:CGRectZero];
cell.backgroundView.backgroundColor = ;
return cell;
</code></pre>
<p>}</p>
<pre><code>- (UITableViewCell *)tableView:(ExpandableTableView *)tableView cellForGroupInSection:(NSUInteger)section
</code></pre>
<p>{
静态 NSString *CellIdentifier = @"GroupCell";</p>
<pre><code>UITableViewCell *cell = ;
UILabel *textLabel = (UILabel *);
NSDictionary *d2 = ;
NSArray *arr2 = ;
NSString *regions = [objectAtIndex:0];
textLabel.textColor= ;
textLabel.text = ];
NSLog(@"Group cell label: %@", textLabel.text);
// We add a custom accessory view to indicate expanded and colapsed sections
cell.accessoryView = [ initWithImage: highlightedImage:];
UIView *accessoryView = cell.accessoryView;
if ([ containsIndex:section]) {
accessoryView.transform = CGAffineTransformMakeRotation(M_PI);
} else {
accessoryView.transform = CGAffineTransformMakeRotation(0);
}
return cell;
</code></pre>
<p>}</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>他,只需要一点点更新一个方法</p>
<pre><code>- (UITableViewCell *)tableView:(ExpandableTableView *)tableView cellForGroupInSection:(NSUInteger)section
{
static NSString *CellIdentifier = @"GroupCell";
UITableViewCell *cell = ;
NSIndexPath *indexPath;
NSString *regions = [objectAtIndex:0];
cell.textLabel.text = ;
// We add a custom accessory view to indicate expanded and colapsed sections
cell.accessoryView = [ initWithImage: highlightedImage:];
UIView *accessoryView = cell.accessoryView;
if ([ containsIndex:section]) {
accessoryView.transform = CGAffineTransformMakeRotation(M_PI);
} else {
accessoryView.transform = CGAffineTransformMakeRotation(0);
}
return cell;
}
</code></pre>
<p>可以帮到你。</p>
<p>HTH,享受编码!</p></p>
<p style="font-size: 20px;">关于ios - 如何使用objective-c用两个NSMutableArray填充可扩展的TableView,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/29667542/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/29667542/
</a>
</p>
页:
[1]