Objective c 如何不使用dequeueReusableCellWithIdentifier?
我有一个小的表视图,最多10个项目,我不想使用Objective c 如何不使用dequeueReusableCellWithIdentifier?,objective-c,xcode,uitableview,tableview,Objective C,Xcode,Uitableview,Tableview,我有一个小的表视图,最多10个项目,我不想使用dequeueReusableCellWithIdentifier方法。原因是,每次滚动表视图时,我都会用第一行代替最后一行,这需要几秒钟的时间才能更新回最后一行 我正在使用一个原型单元,并尝试删除: JsonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 但它在表视图中返回空白单元格 这是我的代码: - (UITableView
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;
}
但在本例中,我得到了故事板中的原型单元。它不是空的,但没有填充数据
谁能告诉我我做错了什么
更新****2014年10月10日*******
以下是可能所有代码都会有所帮助:
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
返回myObject.count;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*CellIdentifier=@“Cell”
JsonTableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[JsonTableViewCell alloc]initWithStyle:
UITableViewCellStyleSubtitle重用标识符:CellIdentifier];
}
调度队列=调度获取全局队列(调度队列优先级高,0ul);
调度异步(队列^{
NSDictionary*tmpDict=[myobjectobjectatindex:indexath.row]
NSMutableString*文本;
text=[NSMutableString stringWithFormat:@“%@”,
[tmpDict objectforkeydsubscript:title]
NSMutableString*详细信息;
详细信息=[NSMutableString stringWithFormat:@“%@”,
[tmpDict objectForKey:content]]
NSURL*url=[NSURL URLWithString:[tmpDict objectForKey:缩略图]];
NSData*data=[NSData dataWithContentsOfURL:url];
UIImage*img=[[UIImage alloc]initWithData:data]
NSString*titleStrip=[[text description]stringByReplacingOccurrencesOfString:@''with string:@''
NSString*detailStrip=[[detail description]stringByReplacingOccurrencesOfString:@''和String:@''
调度同步(调度获取主队列()^{
cell.titreNews.text=titleStrip
cell.detailNews.textAlignment=NSTextAlignmentJustified
cell.detailNews.text=detailStrip
UIImage*image0=[UIImage ImageName:@“video.png”]
如果(img!=nil){
cell.imageNews.image=img;
}
否则{
cell.imageNews.image=image0;
}
}));
}))
[cell setAccessoryType:UITableViewCellAccessoryNone]
返回单元;
}
首先,欢迎来到Stack Overflow
第二,我强烈建议不要禁用排队。苹果对预期行为的要求是出了名的严格,试图以不同的方式重新处理基本的UI元素(如TableView)很容易被拒绝。另外,退出队列是一件好事,它有助于降低内存使用率,并总体上简化工作。找到一种设计您自己的代码的方法,使其能够按照预期的方式与出列过程一起工作,这样做要好得多
也就是说,据我所知,您所需要做的就是省略
dequeueReusableCellWithIdentifier
行,它应该可以工作<代码>单元格每次都是nil
,因此每次都会从头开始重新初始化。此代码块永远不会被调用,因为您在它之前实例化了一个单元格(单元格永远不会为nil)
如果不使用出列方法,请不要调用它们。将您的方法更改为:
- (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;
}
不能将在故事板中创建的原型单元出列。最后一行显示陈旧数据的原因是,如果这部分代码:
if(cell==nil){cell.title.text=titleString}
。这意味着您仅在分配新单元格时设置单元格标题文本(基本上跳过任何已出列的单元格)。如果去掉“零”复选框,你就可以开始了。您好,谢谢您的帮助,但它不起作用。Thermaple不会拒绝那些不将表视图单元格出列的应用程序。这是一个完全可选的性能优化。@FruityGeek我完全同意,我的评论只是建议对改变建议行为的心态保持谨慎。我在最后给出了答案,因为在这个特殊的例子中,这很好。@Nerrolken谢谢你的欢迎,我知道排队不是最好的方法,但是有一个单元格在滚动时需要几秒钟才能更新,这不是很好。我只有10个电池,所以在4S上你经常会注意到这个问题。谢谢你花时间帮我解决这个问题,但它对我不起作用。如果我这样做了,我的手机到处都是空白的。
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;
}