objective-c – 如何不使用dequeueReusableCellWithIdentifier?
我有一个小表视图,最多可能有10个项目,我不想使用dequeueReusableCellWithIdentifier方法.原因是,每次我滚动表视图时,我都会有第一行代替最后一行,这需要几秒钟的时间来更新以获得最后一行的更新.
我正在使用原型单元,我尝试删除: JsonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 但它在表视图中返回空白单元格. 所以这是我的代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell"; JsonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell=[[JsonTableViewCell alloc]initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; } 我也试着保持 JsonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 并配置单元格如: if (cell == nil) { cell.title.text = titleStrip; } 但是在这种情况下,我在故事板中得到了原型单元格.它不是空白,但没有填充数据. 谁能告诉我我做错了什么? 更新**** 10.10.2014 ******* 也许所有代码都可以帮助: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return myObject.count; }
解决方法
永远不会调用此代码块,因为您在它之前实例化一个单元格(单元格永远不是nil).
if (cell == nil) { cell.title.text = titleStrip; } 如果您不使用它们,请不要调用出列方法.将您的方法更改为: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //Don't even try to dequeue,just create new cell instance JsonTableViewCell *cell = [[JsonTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; cell.title.text = titleStrip; return cell; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |