gpt4 book ai didi

ios - tableview 添加自定义 tableview 单元格超过 500 然后工作缓慢?

转载 作者:行者123 更新时间:2023-11-29 02:07:50 26 4
gpt4 key购买 nike

我已经在 iOS 的 obj-c 中制作了 UITableView,我的数组包含超过 500 个元素。Tableview cell 是可编辑的,在单元格中插入行,用键盘打开 textview 和 picker-view 然后应用变慢。我的 CPU 内存使用率也达到了 100%。

我必须管理我的应用 CPU 内存使用情况。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
CGFloat TableCellHeight = 0.000;
for (int i=0; i<arrQuestions.count; i++) {
templateRow *object = [arrQuestions objectAtIndex:i];
CGFloat height2= object.rowHeight ;
TableCellHeight = TableCellHeight+height2;
}
tvQuestion.frame=CGRectMake(tvQuestion.frame.origin.x, tvQuestion.frame.origin.y, tvQuestion.frame.size.width, TableCellHeight+footer.view.frame.size.height+footer.view.frame.size.height);
height=tvQuestion.frame.origin.y+tvQuestion.frame.size.height;
scrollView.contentSize=CGSizeMake(320,height);
return arrQuestions.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
templateRow *object = [arrQuestions objectAtIndex:indexPath.row];
CGFloat height= object.rowHeight ;
return height;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"customCell";
templateRow *object = [arrQuestions objectAtIndex:indexPath.row];
customeCellAnswer *cell = (customeCellAnswer *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray * topLevelObjects;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"customeCellAnswer" owner:self options:nil];
}
else {
topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"customeCellAnswer_ipad" owner:self options:nil];
}
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (customeCellAnswer *)currentObject;
NSLog(@"CustomCell:%@",currentObject);

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
}
else {
[cell setFrame:CGRectMake(0,0,750,100)];
}

break;
}
}
}

if (object.rowType==10){
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
cell.delegate=self;
[cell setDataRow:object];
[cell configureCell];

return cell;
}

最佳答案

你在做什么绝对是奇怪的。 numberOfRowsInSection 不应有任何副作用,例如更改框架大小。通常,您的 numberOfRowsInSection 代码应该是一行

return arrQuestions.count;

关于ios - tableview 添加自定义 tableview 单元格超过 500 然后工作缓慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29606994/

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