ios - 加载更多单元格 UITableView

标签 ios uitableview

我正在尝试将 Load More Cell 添加到我的表格 View 中。从 5 行开始,当我单击“加载更多单元格”并添加更多 5 行时。没有负载的情况下一切正常,更多单元格有图像,但我不想要它。我试图修复它,但它不起作用。

表格开始 http://i.stack.imgur.com/Ld2ED.png

单击“加载更多单元格”后的表格 http://i.stack.imgur.com/A5xjE.png

这是我的cellForRowAtIndexPath:

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

#define IMAGE_VIEW_TAG 99
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (indexPath.section == 0) {
        //create new cell
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        //add AsyncImageView to cell
        AsyncImageView *imageView = [[AsyncImageView alloc] initWithFrame:CGRectMake(5.0f, 5.0f, 50.0f, 50.0f)];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.clipsToBounds = YES;
        imageView.tag = IMAGE_VIEW_TAG;
        [cell addSubview:imageView];
        [imageView release];

        //common settings
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.indentationWidth = 44.0f;
        cell.indentationLevel = 1;
        //get image view
        AsyncImageView *imgView = (AsyncImageView *)[cell viewWithTag:IMAGE_VIEW_TAG];

        //cancel loading previous image for cell
        [[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:imgView];

        //load the image

        imgView.imageURL = [imageURLs objectAtIndex:indexPath.row];

        //display image path
        cell.textLabel.text = [tableData objectAtIndex:indexPath.row ];


    }


   else if (indexPath.section == 1) {

        cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"Load More...", @"The text to display to load more content"), kNumberOfItemsToAdd];
        cell.imageView.image = Nil;
        cell.textLabel.textColor = [UIColor colorWithRed:0.196f green:0.3098f blue:0.52f alpha:1.f];
        cell.textLabel.font = [UIFont boldSystemFontOfSize:12.f];

    }

节数

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (numberOfItemsToDisplay == [tableData count]) {
        return 1;
    }
    return 2;
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    return 5;
//    return tableData.count;
    if (section == 0) {
        return numberOfItemsToDisplay;
    } else {
        return 1;
    }


}

最佳答案

替换这个:

else if (indexPath.section == 1) {
  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  ...
  ...
  ...
}

关于ios - 加载更多单元格 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20529200/

相关文章:

ios - 调用电话操作无法快速工作

ios - 国际化问题排查

ios - Xamarin 表单 : Webview showing slight black line at bottom

ios - 更改 UITableViewCell 中选择的图像(swift 3 xcode)

ios - 使用 Autolayout 时,单元格高度会随着设备高度的变化而变化吗?

swift - accessoryButtonTappedForRowWithIndexPath 在 Swift 2 中返回不需要的索引路径

objective-c - UIPickerView 中不同大小的多个组件/列

android - Android 和 iOS 在 Intent 和后台操作方面的差异

ios - 为什么 awakeFromNib 从 TableView 中的 Cell 调用两次?

ios - 像 App Store 一样的 UITableView 范围栏?