Cell在iOS中成为TableView的Black

时间:2014-10-29 06:32:46

标签: ios iphone

我在iOS中使用tableview。我在数组上得到10个元素,之后当我是表格的最后一个元素时,我得到更多10个元素。它的工作正常,但有些细胞重叠,颜色为黑色。细胞重叠在几秒后变得正常,但黑色仍然存在。我在iOS中更新。请帮助。

- (void)getNewMailFromBottom
{
    if (!isFinished && !isSideMenu && !searching) {
        NSInteger resultsSize = [foldersDataArray count];
        NSInteger count=0;
        NSMutableArray *tempMailArray = (NSMutableArray *)[NSArray arrayWithArray:(NSArray *)[dataBase getFolderMails:[mailBoxAccountId integerValue]:currentFolderLocalId:[foldersDataArray count]:10]];
        if ([tempMailArray count]==0 &&[appDelegate internetConnection] && [Globals getAuthenticationTicket] && ![[Globals getAuthenticationTicket] isEqualToString:@""] && ([[NSUserDefaults standardUserDefaults]boolForKey:@"ALL_MAILS"] || [[NSUserDefaults standardUserDefaults]boolForKey:@"DEFAULT_MAILS"]) && currentFolderLocalId !=appDelegate.draftLocalId && currentFolderLocalId != appDelegate.localOutboxLocalId) {
            [self getAllFolderDataDetail :currentFolderId:YES];
        } else {
            for (NSDictionary *dict in tempMailArray) {
                if (![foldersDataArray containsObject:dict]) {
                    [foldersDataArray addObject:[dict objectForKey:@"mailDetail"]];
                    count++;
                }
            }
            NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];
            for (NSInteger i = resultsSize; i < resultsSize + count; i++)
                [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
            [myTableView insertRowsAtIndexPaths:arrayWithIndexPaths withRowAnimation:UITableViewRowAnimationFade];
            [pullToRefreshManager tableViewReloadFinished];
        }
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableCell";

    SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
        cell =[nib objectAtIndex:1];
        cell.selectionStyle=UITableViewCellAccessoryNone;



    NSInteger sectionsAmount = [tableView numberOfSections];
      NSInteger rowsAmount = [tableView numberOfRowsInSection:[indexPath section]];

    if ([indexPath section] == sectionsAmount - 1 && [indexPath row] == rowsAmount-1) {
        NSLog(@"hello");

        [refreshBottomConnection cancel];
        [self getNewMailFromBottom];
        [pullToRefreshManager setPullToRefreshViewVisible:NO];    }

    return cell;
}

3 个答案:

答案 0 :(得分:2)

   {
        double delayInSeconds = 0.30;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

        [refreshBottomConnection cancel];
        [self getNewMailFromBottom];
      //  [pullToRefreshManager setPullToRefreshViewVisible:NO];

   });

答案 1 :(得分:0)

使用可重复使用的表格单元格,并使用

在UITableView上进行编辑
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

并为UITableViewCellEditingStyleInsert添加条件:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger row = [indexPath row];
    if (editingStyle == UITableViewCellEditingStyleDelete) {
       //Now you needn't
    }else if(editingStyle == UITableViewCellEditingStyleInsert ){
        NSArray *insertIndexPaths = [NSArray arrayWithObjects:indexPath,nil];
        [self.list insertObject:@"new Cell" atIndex:row];//The list is the cell data source array
        [tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationMiddle];
    }
}

除了在此功能中编辑单元格视图外:

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

答案 2 :(得分:0)

您的代码存在问题。请查看以下代码。

if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
    cell =[nib objectAtIndex:1];
    cell.selectionStyle=UITableViewCellAccessoryNone;
}

你错过了最后一个括号......