Iphone 在UITableView中显示节数据

Iphone 在UITableView中显示节数据,iphone,xcode,uitableview,Iphone,Xcode,Uitableview,我不熟悉分段UITableVIew。我的问题是我有一个名为stringsArray的数组,它的字符串如下 NSMutableArray *dataArray = [[NSMutableArray alloc] initWitObjects:@"apple1",@"apple2",@"ball",@"cat",@"cat2",nil]; //I have many strings. 我需要像下面这样显示数据 我需要在A部分下显示apple1,apple2 我需要像这样在B区下面展示球 有人能帮我

我不熟悉分段UITableVIew。我的问题是我有一个名为stringsArray的数组,它的字符串如下

NSMutableArray *dataArray = [[NSMutableArray alloc] initWitObjects:@"apple1",@"apple2",@"ball",@"cat",@"cat2",nil]; //I have many strings.
我需要像下面这样显示数据

我需要在A部分下显示apple1,apple2 我需要像这样在B区下面展示球


有人能帮我做这件事吗

基本上,您需要在stringsForSection1和stringsForSection2数组中获取字符串。根据您的喜好更改名称;)然后实现UITableViewDataSourceProtocol。您需要实现两种方法:

-tableView:NumberForrowsInstruction:

-tableView:cellForRowAtIndexPath:

以下是参考资料的链接: 在tableView:cellForRowAtIndexPath中,(NSIndexPath*)indexPath将包含一个节和一个行属性。根据这些值,您可以从stringsForSection1或stringsForSection2加载数据,如下所示:

if(indexPath.section==1){
    cell.textLabel.text = [stringsForSection1 objectAtIndex:indexPath.row];
}else if(indexPath.section==2){
    cell.textLabel.text = [stringsForSection2 objectAtIndex:indexPath.row];
}

玩得开心

基本上,您需要在stringsForSection1和stringsForSection2数组中获取字符串。根据您的喜好更改名称;)然后实现UITableViewDataSourceProtocol。您需要实现两种方法:

-tableView:NumberForrowsInstruction:

-tableView:cellForRowAtIndexPath:

以下是参考资料的链接: 在tableView:cellForRowAtIndexPath中,(NSIndexPath*)indexPath将包含一个节和一个行属性。根据这些值,您可以从stringsForSection1或stringsForSection2加载数据,如下所示:

if(indexPath.section==1){
    cell.textLabel.text = [stringsForSection1 objectAtIndex:indexPath.row];
}else if(indexPath.section==2){
    cell.textLabel.text = [stringsForSection2 objectAtIndex:indexPath.row];
}

玩得开心

下面是两个很好的教程,您可以从中找到问题的完整解决方案。如果您更改了数据结构,使
dataArray
中的每个对象都是
NSMutableArray
,希望此帮助将变得更容易操作和理解。
dataArray
中的每个数组将表示一个节,并且只包含该节行的字符串。将每个节的数据保存在不同的NSMutable数组中。如果您这样做,您还可以更轻松地计算每个部分中要显示的行数。下面是两个很好的教程,您可以从中找到问题的完整解决方案。如果您更改了数据结构,使每个对象都在
dataArray
也是一个
NSMutableArray
dataArray
中的每个数组将表示一个节,并且只包含该节行的字符串。将每个节的数据保存在不同的NSMutable数组中。如果这样做,您还可以更轻松地计算每个部分中要显示的行数。