Как управлять cellForRowAtIndexPath для tableViewIndexSearch? - PullRequest
0 голосов
/ 26 мая 2011

как управлять cellForRowAtindexPath Значение для TableViewIndexПоиск мой код:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

    alphabetDict = [NSDictionary dictionaryWithObject:tempArray forKey:@"alphabet"];

    NSLog(@"alphabetDict Is: %@", alphabetDict);

    [listArray  addObject:alphabetDict];

    NSLog(@"listArray Is: %@", listArray);

    return tempArray;

} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{      
    return 26; 
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.frame.size.width,30)] autorelease];



    UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, -5, headerView.frame.size.width-120.0, headerView.frame.size.height)];


    for(section ; section <=[self.tempArray count];section++)

    {

        headerLabel.textAlignment = UITextAlignmentLeft;


        headerLabel.text = [self.tempArray objectAtIndex:section];

        headerLabel.textColor = [UIColor whiteColor];

        headerLabel.backgroundColor = [UIColor clearColor];

        headerLabel.font = [UIFont fontWithName:@"Verdana Bold" size:11];

        [headerView setBackgroundColor:[UIColor orangeColor]];

//        NSLog(@"headerLabel.text:%@", headerLabel.text);
        [headerView addSubview:headerLabel];

        [headerLabel release];


        return headerView;

    } 

    return headerView;

}


-(float)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {



    return  23.0;

}

// --------- TableView Delegate and DataSource-----------

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

{
    return [xmlParseArray count];

}


// Customize the appearance of table view cells.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    DirectoryCustomCell *directoryCustomCell =(DirectoryCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (directoryCustomCell == nil) {

        directoryCustomCell = [[[DirectoryCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        directoryCustomCell.selectionStyle = UITableViewCellEditingStyleNone;


    }

    UIImageView *searchImg = [[UIImageView alloc]initWithFrame:CGRectMake(292, 0, 28, 360)];

    searchImg.image = [UIImage imageNamed:@"searchindex.png"];

    [directoryCustomCell addSubview:searchImg];



    NSString *companyName = [[xmlParseArray objectAtIndex:indexPath.row ]objectForKey:@"firstname"];
//    NSLog(@"companyName :%@",companyName);

    NSString *flName = [[xmlParseArray objectAtIndex:indexPath.row ]objectForKey:@"title"];

    [directoryCustomCell setDataForEvent1:companyName venue:flName];



    return directoryCustomCell;

}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    return [[collation sectionTitles] objectAtIndex:section];

}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {

    return [collation sectionForSectionIndexTitleAtIndex:index];

}

Я хочу показать в отсортированном виде (я имею в виду заголовок раздела A, имя которого начинается с A и т. Д.).

Между заголовком заголовка от A до B эти данные являются общими для каждого раздела, но мне нужны только те, которые начинаются с A в SectionHeadertitle A и начинаются с B в заголовке B.

1 Ответ

0 голосов
/ 26 мая 2011
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
    switch(indexPath.section)
{
// Configure based on section
// Get details corresponding to section
}
    // configure cell and return cell
}

Взгляните на этот учебник

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...