我已经在UITableView
中为iOS设置了obj-c
,我的数组包含了超过500个元素。
Tableview cell
是可编辑的,在单元格中插入行,使用键盘和选择器视图打开textview然后应用程序变慢。我的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;
}
答案 0 :(得分:1)
你在做什么绝对是奇怪的。 numberOfRowsInSection不应有任何副作用,例如更改帧大小。通常,numberOfRowsInSection的代码应该是一行
return arrQuestions.count;