English 中文(简体)
UITableView出现在空洞囚室里
原标题:UITableView appears with empty cells

I have a problem displaying UITableView: Some cells are empty, and content in cells becomes visible only after scrolling (if empty cell scrolls out of the screen and then goes back). I Can t understand what might be the problem.

www.un.org/spanish/ecosoc 我的法典是:。

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self updateFilesList];
    [tableView reloadData];
}

- (void) viewDidAppear:(BOOL)animated
{
    animated = YES;
    [self updateFilesList];
    [self.tableView reloadData];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.filesList retain];

    NSString *title = [self.filesList objectAtIndex:indexPath.row];
    title = [title stringByDeletingPathExtension];
    title = [title lastPathComponent];
    if (title.length >33) {
        title = [title substringFromIndex:33];
    }

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    [cell.imageView setImage:[UIImage imageNamed:@"oie_png-1.png"]];
    cell.textLabel.text = title;

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    return cell;
}

Thank you in advance for your suggestions!

最佳回答

Well, you have the cell customization code that happens before you create the cell.

更改如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.filesList retain];

    NSString *title = [self.filesList objectAtIndex:indexPath.row];
    title = [title stringByDeletingPathExtension];
    title = [title lastPathComponent];
    if (title.length >33) {
        title = [title substringFromIndex:33];
    }

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    // This part creates the cell for the firs time
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // This part customizes the cells
    [cell.imageView setImage:[UIImage imageNamed:@"oie_png-1.png"]];
    cell.textLabel.text = title;


    return cell;
}
问题回答

The problem is that you make

[cell.imageView setImage:[UIImage imageNamed:@"oie_png-1.png"]];
cell.textLabel.text = title;

before

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

改变顺序。 正在发生的是,你第一次执行表格。 你们从来不去在座。 当你重新使用电池时,由于电池!= 无

You need to put these lines

[cell.imageView setImage:[UIImage imageNamed:@"oie_png-1.png"]];
cell.textLabel.text = title;

after the if(){...} condition.

第一个穿过囚室为零。 在<代码>之前的这些行文不成。 因此,你看着空洞的囚室。

A brief question

为什么请<代码>。 名单保留了?

希望会有所帮助。





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签