Ios 使用2个NSMuteableArray中的行创建多个UITableView节
我有两个Ios 使用2个NSMuteableArray中的行创建多个UITableView节,ios,iphone,uitableview,Ios,Iphone,Uitableview,我有两个NSMuteableArrays。第一个(nameOfSectionArray)收集每个新节的名称。第二个(numberOfRowsArray)收集每个部分应该有多少行。我在使用这些数组创建一个UITableView时遇到问题,该视图的节数和行数都正确 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [nameOfSectionsArray count]; } - (NSInt
NSMuteableArray
s。第一个(nameOfSectionArray)收集每个新节的名称。第二个(numberOfRowsArray)收集每个部分应该有多少行。我在使用这些数组创建一个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
,为我将拥有的每一行添加一个对象。然后我把这个加到原来的数字rowsarray上
这就是我所做的
-(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];
}