代码之家  ›  专栏  ›  技术社区  ›  dpigera

目标C部分标题显示不正确?

  •  0
  • dpigera  · 技术社区  · 16 年前

    我有一个 火车站 对象定义为:

    @interface RFStation : NSObject {
        NSString *stationID; 
        NSString *callsign; 
        NSString *logo; 
    @end
    

    我还有一个名为' 统计人员 '这是桩号对象的列表。此列表按字母顺序排列' 呼号 '.

    我还有另一个NSArray叫' 将军 ,包含字母“A”到“Z”

    我想创建一个UITableView,其中的节头a-Z对应于每个呼号的第一个字母。

    我目前有这些方法&定义的对象:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return [generalList count];
    
    }
    
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
        return [generalList objectAtIndex:section];
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
        NSPredicate *filter = [NSPredicate predicateWithFormat:@"callsign beginswith[cd] %@",[generalList objectAtIndex:section]];
        return [[stationList filteredArrayUsingPredicate:filter] count];
    }
    

    当然还有:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        RFStation *aStation = [stationList ObjectAtIndex:[indexPath row]];
        static NSString *identity = @"MainCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identity];
    
        if(cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.0, 0.0) reuseIdentifier:identity] autorelease];
        }
        cell.text = aStation.callsign;
    
        return cell;
    }
    

    然而,我的标题似乎没有正确地对NSMutableArray数据进行排序。我的代码有什么问题(我怀疑它是谓词)

    1 回复  |  直到 12 年前
        1
  •  0
  •   V1ru8    16 年前

    你读了吗 [stationList ObjectAtIndex:[indexPath row]] .但是NSIndexPath对象的行不是全部,而是节中的行。你必须实施 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 并返回每个节的确切行数。所以你必须自己处理哪个单元在哪个部分。

    我更喜欢字母表中每一个字母都有一个键的NSArray字典,作为他们的对象NSArray的Station对象。