【问题标题】:Tableview refreshes data every timeTableview每次刷新数据
【发布时间】:2013-07-25 00:42:55
【问题描述】:

首先,我有一个幻灯片应用程序,还有一个表格视图。 通过点击主菜单中的单元格“CellInMainMenu”,应用程序通过推送打开 tableview“TV1”,并且此 tableview(“TV1”) 中的单元格通过数组填充数据。当我将这个 tableview("TV1") 滑动到一边,然后再次点击单元格“CellInMainMenu”时,应用程序再次打开 tableview("TV1"),但是! Tableview("TV1") 再次开始用信息填充单元格!如何让应用在启动应用时一次性加载所有数据?

(我真的很抱歉我的英语不是我的语言)

有人可以帮帮我吗?

“TV1”中的代码:

- (void)viewDidLoad    
{    
[super viewDidLoad];
daoDS = [[SampleDataDAO alloc] init];
self.ds = daoDS.PopulateDataSource;    
}

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

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

SampleData *sample = [self.ds objectAtIndex:indexPath.row];
cell.textLabel.text = sample.HeroesName;
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont fontWithName:@"Trajan-Regular" size:18.0f];

return cell;

}

(所有应用程序都可以正常工作,我只想知道如何只加载一次,但不是每次都加载)

【问题讨论】:

    标签: ios uitableview viewdidload


    【解决方案1】:

    问题不在于您的表格视图代码,而在于您如何推送它。如果你调用一个 segue,它总是会创建一个新的。

    相反,您只能在第一次推送它,保留对它的引用,然后根据您选择的菜单更新它。一些自定义委托@protocol 可能是最好的模式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-13
      • 2017-09-22
      • 2011-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      相关资源
      最近更新 更多