Iphone 如何在UItableview中按节获取值?

Iphone 如何在UItableview中按节获取值?,iphone,uitableview,xcode4.2,Iphone,Uitableview,Xcode4.2,我正在尝试制作一个应用程序,其中我使用了分组表视图。在这个应用程序中,我创建了第一个字母来自数组的部分,它做得非常完美。 代码如下 sections=[[NSMutableArray alloc] init]; for(int i=0;i<[PdfNames count]; i++) { NSString *s=[[PdfNames objectAtIndex:i] substringToIndex:1]; NSPredicate *p=[NSPredica

我正在尝试制作一个应用程序,其中我使用了分组表视图。在这个应用程序中,我创建了第一个字母来自数组的部分,它做得非常完美。 代码如下

sections=[[NSMutableArray alloc] init];

for(int i=0;i<[PdfNames count]; i++)
{

 NSString *s=[[PdfNames objectAtIndex:i] substringToIndex:1];        

    NSPredicate *p=[NSPredicate predicateWithFormat:@"letter like '%@'",s];

    NSArray *check=[sections filteredArrayUsingPredicate:p];


    if([check count]<1)

    {
         dict=[[[NSMutableDictionary alloc] init] autorelease];
        [dict setValue:s forKey:@"letter"];
        [sections addObject:dict];

    }


}
sections=[[NSMutableArray alloc]init];

对于(inti=0;i请尝试以下代码及其基本逻辑,希望您能够理解

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section == 0) {
       return 10;  // Number of rows in section.
    } else if (section == 1) {
       return 5;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;   // Let say we have two section.
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell;
    if (indexPath.section == 0) {
        // Assign your data
    } else if (section == 1) {
       // Assign your data
    }
}

类似地,您可以在
didSelectRowAtIndexPath:
方法上检查
表节
,您正在创建一个数组
,该数组当然是空的。然后根据
创建一个数组
检查
。因此它也将是空的。
[检查计数]
将始终为零。不会创建任何
NSDictionary


清楚吗?

看来这个答案与这个问题完全无关。@Mundi:来自标题“如何在UItableview中按节获取值?”我认为用户不知道如何按照表格部分分隔数组。也许你是对的…但这仍然没有帮助。尽管尝试得很好。我认为问题标题和描述令人困惑。你能告诉我你面临什么样的问题吗?现在我对你的问题标题和描述感到困惑。我现在有一个数组Pdf名称我所做的是我创建了一个字典,其中我需要第一个字母,以便它可以用作节头,问题是我无法从该特定节的数组中插入Pdf名称:)是一个问题还是两个不同的问题?(1) 无法将后面的字母设置为标题。或(2)无法在表节的行中设置特定数据??值得注意的是,我为该部分设置了数据,因此我希望您能够理解我在回答中所述的逻辑。或者你想要别的东西。