Iphone 每次cellForRowAtIndexPath调用时,在cellForRowAtIndexPath上单击UITableViewCell
我创建了一个自定义UITableView单元,它有4-5个不同的组件。有时我从CGRectMake创建UIView,有时根据一些x、y坐标计算来定位一些UIImage。由于cellForRowAtIndexPath每次都创建一个新的单元格,所以一切都正常。但是,当我打算基于“dequeueReusableCellWithIdentifier”重用单元格时,UI会变得一团糟。以前的rect Make从未被删除,早期UIView的定位也表现得很奇怪。尽管单元索引是变化的,但它并不反映所绘制图像的协调 在每个CellForRowatineXpath中创建UITableViewCell在3GS和4G中运行良好,但在3G中非常烦人且速度非常慢。我怀疑这种行为是因为在每次调用中都创建了CellForRowatineXpath。有谁能帮我找出这个问题吗 这就是我现在所做的Iphone 每次cellForRowAtIndexPath调用时,在cellForRowAtIndexPath上单击UITableViewCell,iphone,iphone-sdk-3.0,uitableview,ios4,Iphone,Iphone Sdk 3.0,Uitableview,Ios4,我创建了一个自定义UITableView单元,它有4-5个不同的组件。有时我从CGRectMake创建UIView,有时根据一些x、y坐标计算来定位一些UIImage。由于cellForRowAtIndexPath每次都创建一个新的单元格,所以一切都正常。但是,当我打算基于“dequeueReusableCellWithIdentifier”重用单元格时,UI会变得一团糟。以前的rect Make从未被删除,早期UIView的定位也表现得很奇怪。尽管单元索引是变化的,但它并不反映所绘制图像的协调
CustomNoteCell *cell = nil;
if (cell == nil) {
cell = (CustomNoteCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomNoteCell" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (CustomNoteCell *) currentObject;
break;
}
}
}
//rest of the codes go here like
CGSize maximumLablelSize = CGSizeMake(296, 1000);
CGSize expectedLabelSize = [alue sizeWithFont:cell.customCellNoteText.font constrainedToSize:maximumLablelSize lineBreakMode:cell.customCellNoteText.lineBreakMode];
CGRect newFrame = cell.customCellNoteText.frame;
newFrame.size.height = expectedLabelSize.height;
cell.customCellNoteText.frame = newFrame;
cell.customCellNoteText.text = noteValue;
cell.uiViewContrlloer = self;
CGRect addressRect = cell.address.frame;
addressRect.origin.y = newFrame.origin.y + newFrame.size.height + 10;
cell.address.frame = addressRect;
谢谢我想你打错了出列手机。你应该把它放在
前面,如果(cell==nil)
正如tia提到的,你的单元格总是为nil。你应该早点下队
CustomNoteCell *cell = (CustomNoteCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (! cell) {
cell = [[[CustomNoteCell alloc] initWithReuseIdentifier:CellIdentifier] autorelease];
是的。我已经发布了工作示例。在这种情况下,它可以正常工作。但在3G中速度较慢,但在3GS和4G中工作完美。但是,当我在if(cell==nil)之前将单元格出列时,我得到了我所讨论的问题。这就是我的问题。我想在这一行上面退出队列,它应该能按预期工作,但目前不行。你能发布你的实际代码吗?这些代码不能工作,而且格式也不能?我的眼睛现在疼了…很抱歉。格式化了,谢谢你,保罗。当我打算基于“dequeueReusableCellWithIdentifier”重用单元格时,UI会变得一团糟。这就是问题所在。什么是“一团糟?”这种方法会发生什么?静态NSString*CellIdentifier=@“CustomNoteCell”;CustomNoteCell*单元格=(CustomNoteCell*)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier];如果(!cell){cell=[[NSBundle mainBundle]loadNibNamed:@“CustomNoteCell”所有者:self options:nil]lastObject];}//自定义单元格…这里的问题是定位出错。它在每个单元格中随机抽取内容。您如何设置单元格的高度?能否将一些布局逻辑推送到已创建的CustomNoteCell类中?i、 e.[cell setNoteText:noteValue]?