gpt4 book ai didi

ios - 在 iOS7 中滚动之前,uitableviewcell 不会更新

转载 作者:行者123 更新时间:2023-11-28 22:06:56 27 4
gpt4 key购买 nike

我有一个标准的 UITableView,我在其中创建如下所述的单元格。这在 iOS6 中工作得很好,但在 iOS7 上,detailTextLabel 不会更新,直到我滚动并且需要更改的单元格不在 View 中。

在调试它时,我看到当我调用 [tableview reloadData] 时,它每次都会在 ios7 上创建一个新单元格,而在 ios6 上它会“deque(s)”之前加载的单元格等等调用 reloadData 它会显示更新的文本并按预期删除加载图像。为什么单元格在 ios7 上没有“dequed”?

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

{

static NSString *CellIdentifier = @"CEllId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"MainText";

if (self.requestInProgress)
{

cell.detailTextLabel.text = @"Processing...";

// show loading spinner
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryView = spinner;
[spinner startAnimating];
}
else
{
// display the status
cell.detailTextLabel.text = @"the text returned";

// hide loading indicator & show disclosure indicator
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

return cell;
}

最佳答案

代码很好。我认为单元格的高度存在问题。你只需修复高度单元。然后它会工作正常。方法名称:heightForRowAtIndexPath

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CEllId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"MainText";

if (YES)
{

cell.detailTextLabel.text = @"Processing...";

// show loading spinner
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryView = spinner;
[spinner startAnimating];
}
else
{
// display the status
cell.detailTextLabel.text = @"the text returned";

// hide loading indicator & show disclosure indicator
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

return cell;
}

关于ios - 在 iOS7 中滚动之前,uitableviewcell 不会更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23744542/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com