繁体   English   中英

使用2个NSMuteableArrays中的行创建多个UITableView节

[英]Create multiple UITableView sections with rows from 2 NSMuteableArrays

我有两个NSMuteableArray 第一个(nameOfSectionArray)收集每个新节的名称。 第二个(numberOfRowsArray)收集每个节应具有的行数。 我在使用这些数组创建UITableView时遇到麻烦,该UITableView的节数正确,行数正确。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [nameOfSectionsArray count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [numberOfRowsArray objectAtIndex:section];
}


-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return [nameOfSectionsArray objectAtIndex:section];
}

该程序不会崩溃。 我只是没有任何行。 所有部分均正确显示。 有人可以帮助我使用我的numberOfRowsInSection方法吗?

谢谢!

我想到了。 我意识到我只是在创建一个NSMuteableArry ,该数字将包含表示我有多少行的数字。 将来这将是一个问题。

相反,我制作了另一个NSMuteableArry ,为需要的每一行添加了一个对象。 然后我将其添加到原始numberOfRowsArray

这就是我所做的。

-(void) newRows
{

int i=0;
UITableViewCell *cell = [[UITableViewCell alloc]init];
NSMutableArray *allCells = [[NSMutableArray alloc]init];

while (i<numberOfRows)
{
    [allCells insertObject:cell atIndex:[allCells count]];
    i++;
}

[numberOfRowsArray insertObject:allCells atIndex:[numberOfRowsArray count]];
}

然后

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return [[numberOfRowsArray objectAtIndex:section] count];
}

这成功了:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM