[英]Adding data to 2 Sections of UITableView from SINGLE nsmutablearray
我想知道如何在一個數據源的不同部分列出tableView中的數據。
我看到的所有例子都有數組=節數。 我想要的是假設我有一個3d nsmutableArray。
If dArray.Id = 1 { //add to first section of UITableView }
else add to Section 2 of UITableView.
它可能是可行的,但我需要一個方向。
是的,有可能做到這一點。
您可以擁有一個包含整個內容的NSMutableArray
( resultArray
)。
然后在cellForRowAtIndexPath
方法中,您可以這樣做
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0)
{
cell.text=[resultArray objectAtIndex:indexPath.row];
}
else if(indexPath.section == 1)
{
cell.text=[resultArray objectAtIndex:(indexPath.row+5)];
}
else if(indexPath.section == 2)
{
cell.text=[resultArray objectAtIndex:(indexPath.row+11)];
}
}
並在numberOfRowsInSection
- (NSInteger)tableView:(UITableView *)tableView1 numberOfRowsInSection:(NSInteger)section {
NSInteger count;
if(section == 0)
{
count=6;
}
else if(section == 1)
{
count=6;
}
else if(section == 2)
{
count=4;
}
return count;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.