我正在开发一个应用程序,该应用程序从UITableView
中的服务器加载数据,并且每个单元格都是自定义的。
问题是当我在iPhone 4s上运行这个应用程序时,它很慢并且冻结,但它可以在其他设备上运行而不会冻结或减速。 我的应用程序中有一些图像用于单元格背景。如何解决这个问题?
为什么iPhone 4s的速度很慢?
有没有办法解决这个问题?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ThreadInfo *info=[_fetchedResultsController objectAtIndexPath:indexPath];
//HIDE EXTRA REPLYVIEW
static NSString *cellIdentifier = @"replyview";
IXOutMessageCustomCell *cells = (IXOutMessageCustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cells == nil) {
cells = [[[NSBundle mainBundle] loadNibNamed:@"IXOutMessageCustomCell" owner:self options:nil] objectAtIndex:0];
cells.selectionStyle = UITableViewCellSelectionStyleNone;
}
// if (cells.replyview.hidden == NO) {
cells.replyview.hidden = YES;
//}
if([info.isSystemMessage boolValue])
{
static NSString *cellIdentifier = @"SystemListCell";
IXSystemMessageCustomCell *cell = (IXSystemMessageCustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"IXSystemMessageCustomCell" owner:self options:nil] objectAtIndex:0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.playButton addTarget:self action:@selector(playButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
[self configureSystemCell:cell atIndexPath:indexPath];
return cell;
}
else if([info.isPoll boolValue] || [info.isQuiz boolValue])
{
static NSString *cellIdentifier1 = @"pollCell";
IXPollCustomCell *pollCell = (IXPollCustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier1];
if (pollCell == nil) {
pollCell = [[[NSBundle mainBundle] loadNibNamed:@"IXPollCustomCell" owner:self options:nil] objectAtIndex:0];
pollCell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if([info.pollType isEqualToString:@"Star"])
{
CGFloat cellFrameHeight = pollCell.frame.size.height;//changed
CGFloat cellFrameWidth = pollCell.frame.size.width;//changed
pollCell.starView.frame = CGRectMake(0, cellFrameHeight / 2 +40, cellFrameWidth, 73);
}
[self configurePollCell:pollCell atIndexPath:indexPath];
CGRect dateRect=pollCell.dateLabel.frame;
CGRect lineRect=pollCell.lineImageView.frame;
CGRect visibilityRect=pollCell.visibilityButton.frame;
if([info.pollType isEqualToString:@"Binary"])
{
CGFloat choiceFrameHeight=100;
if (info.image !=nil) {
dateRect.origin.y=pollCell.multiChoiceView.frame.origin.y+choiceFrameHeight+10+10+210;//edited by rsk
lineRect.origin.y=178+100+60+10-1;
visibilityRect.origin.y=pollCell.multiChoiceView.frame.origin.y+choiceFrameHeight+23+10+5+210;//edited by rsk
}
else {
dateRect.origin.y=pollCell.multiChoiceView.frame.origin.y+choiceFrameHeight+10+10;
lineRect.origin.y=178+100+60+10-1;
visibilityRect.origin.y=pollCell.multiChoiceView.frame.origin.y+choiceFrameHeight+23+10+5;//edited by rsk
}
}
else if([info.pollType isEqualToString:@"MultiChoice"])
{
NSMutableArray *optionList=[NSKeyedUnarchiver unarchiveObjectWithData:info.pollOptions];
// CGFloat choiceFrameHeight=pollCell.multiChoiceView.frame.size.height;
CGFloat choiceFrameHeight;
if(optionList.count==3)
{
choiceFrameHeight=140+10+5;//edited by rsk
lineRect.origin.y=178+140+70+6-1;
}
else if(optionList.count==4 )
{
choiceFrameHeight=190+5;//edited by rsk
lineRect.origin.y=178+180+60+30-1;
}
else
{
choiceFrameHeight=220+20+5;//edited by rsk
lineRect.origin.y=178+220+60+40-1;
}
dateRect.origin.y=pollCell.multiChoiceView.frame.origin.y-20+choiceFrameHeight+40;
visibilityRect.origin.y=pollCell.multiChoiceView.frame.origin.y-20+choiceFrameHeight+55; }
else if([info.pollType isEqualToString:@"Star"])
{
if(info.image !=nil)
{
dateRect.origin.y=pollCell.starView.frame.origin.y+pollCell.starView.frame.size.height+10+210;//edited by rsk
visibilityRect.origin.y=pollCell.starView.frame.origin.y+pollCell.starView.frame.size.height+20+5+210;//edited by rsk
} else {
dateRect.origin.y=pollCell.starView.frame.origin.y+pollCell.starView.frame.size.height+10;
visibilityRect.origin.y=pollCell.starView.frame.origin.y+pollCell.starView.frame.size.height+20+5;//edited by rsk
}
lineRect.origin.y=178+75+60-1;
}
else
{
dateRect.origin.y=299-50;
visibilityRect.origin.y=299-40+5;//edited by rsk
lineRect.origin.y=299;
}
pollCell.dateLabel.frame=dateRect;
// pollCell.lineImageView.frame=lineRect;
pollCell.lineImageView.hidden= YES;
pollCell.visibilityButton.frame=visibilityRect;
CGRect visibilityPopupRect=pollCell.visibilityPopupView.frame;
if(info.image !=nil){
visibilityPopupRect.origin.y=visibilityRect.origin.y-visibilityPopupRect.size.height+210;//edited by rsk
} else {
visibilityPopupRect.origin.y=visibilityRect.origin.y-visibilityPopupRect.size.height;
}
pollCell.visibilityPopupView.frame=visibilityPopupRect;
pollCell.bgImageView.frame=pollCell.contentView.frame;
if([info.pollType isEqualToString:@"Star"]) //Star
{
// NSLog(@"STAR LOG %d",cellHeight);
// NSLog(@"STAR LOGss %f",pollCell.frame.size.height);
// NSLog(@"STAR FRAME HEIGHt %f",self.view.frame.size.height);
float framesize = 0.8*self.view.frame.size.height;
if(info.image !=nil)
{
if (info.threadMessage.length > 100){
[pollCell.dateLabel setFrame:CGRectMake(pollCell.dateLabel.frame.origin.x, framesize-50+140+30, pollCell.dateLabel.frame.size.width, pollCell.dateLabel.frame.size.height)];
[pollCell.visibilityButton setFrame:CGRectMake(pollCell.visibilityButton.frame.origin.x,5+framesize-40+140+30, pollCell.visibilityButton.frame.size.width, pollCell.visibilityButton.frame.size.height)];//edited by rsk
[pollCell.visibilityPopupView setFrame:CGRectMake(pollCell.visibilityPopupView.frame.origin.x, framesize-80+150+30, pollCell.visibilityPopupView.frame.size.width, pollCell.visibilityPopupView.frame.size.height)];
} else {
[pollCell.dateLabel setFrame:CGRectMake(pollCell.dateLabel.frame.origin.x, framesize-50+140+10, pollCell.dateLabel.frame.size.width, pollCell.dateLabel.frame.size.height)];
[pollCell.visibilityButton setFrame:CGRectMake(pollCell.visibilityButton.frame.origin.x,5+framesize-40+140+10, pollCell.visibilityButton.frame.size.width, pollCell.visibilityButton.frame.size.height)];//edited by rsk
[pollCell.visibilityPopupView setFrame:CGRectMake(pollCell.visibilityPopupView.frame.origin.x, framesize-80+150+10, pollCell.visibilityPopupView.frame.size.width, pollCell.visibilityPopupView.frame.size.height)];
}
} else {
[pollCell.dateLabel setFrame:CGRectMake(pollCell.dateLabel.frame.origin.x, framesize-50, pollCell.dateLabel.frame.size.width, pollCell.dateLabel.frame.size.height)];
[pollCell.visibilityButton setFrame:CGRectMake(pollCell.visibilityButton.frame.origin.x,5+framesize-40, pollCell.visibilityButton.frame.size.width, pollCell.visibilityButton.frame.size.height)];//edited by rsk
[pollCell.visibilityPopupView setFrame:CGRectMake(pollCell.visibilityPopupView.frame.origin.x, framesize-80, pollCell.visibilityPopupView.frame.size.width, pollCell.visibilityPopupView.frame.size.height)];
}
}
if([info.pollType isEqualToString:@"MultiChoice"] || [info.pollType isEqualToString:@"Binary"] )
{
NSMutableArray *optionList=[NSKeyedUnarchiver unarchiveObjectWithData:info.pollOptions];
if((optionList.count==5) || (optionList.count==10) ) {
if(info.image !=nil){
CGRect adjustVisibility = visibilityRect;
adjustVisibility.origin.y -= 20;
pollCell.visibilityButton.frame=adjustVisibility;
CGRect adjustDate = dateRect;
adjustDate.origin.y -= 20;
pollCell.dateLabel.frame=adjustDate;
visibilityPopupRect.origin.y=visibilityRect.origin.y-visibilityPopupRect.size.height-30;
pollCell.visibilityPopupView.frame=visibilityPopupRect;
}
NSLog(@"nothing");
} else {
float framesize = 0.8*self.view.frame.size.height;
if (info.image != nil) {
if([info.pollType isEqualToString:@"Binary"])
{
float framesize = 0.8*self.view.frame.size.height;
[pollCell.dateLabel setFrame:CGRectMake(pollCell.dateLabel.frame.origin.x, framesize-40+177, pollCell.dateLabel.frame.size.width, pollCell.dateLabel.frame.size.height)];
[pollCell.visibilityButton setFrame:CGRectMake(pollCell.visibilityButton.frame.origin.x,5+framesize-30+177, pollCell.visibilityButton.frame.size.width, pollCell.visibilityButton.frame.size.height)];//edited by rsk
[pollCell.visibilityPopupView setFrame:CGRectMake(pollCell.visibilityPopupView.frame.origin.x, framesize-70+187, pollCell.visibilityPopupView.frame.size.width, pollCell.visibilityPopupView.frame.size.height)];
} else {
[pollCell.dateLabel setFrame:CGRectMake(pollCell.dateLabel.frame.origin.x, framesize-40+200, pollCell.dateLabel.frame.size.width, pollCell.dateLabel.frame.size.height)];
[pollCell.visibilityButton setFrame:CGRectMake(pollCell.visibilityButton.frame.origin.x,5+framesize-30+200, pollCell.visibilityButton.frame.size.width, pollCell.visibilityButton.frame.size.height)];//edited by rsk
[pollCell.visibilityPopupView setFrame:CGRectMake(pollCell.visibilityPopupView.frame.origin.x, framesize-70+210, pollCell.visibilityPopupView.frame.size.width, pollCell.visibilityPopupView.frame.size.height)];
}
} else {
[pollCell.dateLabel setFrame:CGRectMake(pollCell.dateLabel.frame.origin.x, framesize-40, pollCell.dateLabel.frame.size.width, pollCell.dateLabel.frame.size.height)];
[pollCell.visibilityButton setFrame:CGRectMake(pollCell.visibilityButton.frame.origin.x,5+framesize-30, pollCell.visibilityButton.frame.size.width, pollCell.visibilityButton.frame.size.height)];//edited by rsk
[pollCell.visibilityPopupView setFrame:CGRectMake(pollCell.visibilityPopupView.frame.origin.x, framesize-70, pollCell.visibilityPopupView.frame.size.width, pollCell.visibilityPopupView.frame.size.height)];
}
// NSLog(@"framee size %f", self.view.frame.size.height);
if (self.view.frame.size.height <= 480 && (optionList.count ==4 || optionList.count == 8) )
{
if([info.pollType isEqualToString:@"Binary"] && optionList.count ==4){
}else {
if (optionList.count == 8) {
dateRect.origin.y = dateRect.origin.y-50;
visibilityRect.origin.y = visibilityRect.origin.y-50;
pollCell.dateLabel.frame=dateRect;
pollCell.visibilityButton.frame=visibilityRect;
visibilityPopupRect.origin.y=visibilityRect.origin.y-visibilityPopupRect.size.height;
pollCell.visibilityPopupView.frame=visibilityPopupRect;
} else {
if (info.image !=nil) {
CGRect adjustDate = dateRect;
adjustDate.origin.y -= 28;
pollCell.dateLabel.frame=adjustDate;
CGRect adjustVisibility = visibilityRect;
adjustVisibility.origin.y -= 28;
pollCell.visibilityButton.frame=adjustVisibility;
visibilityPopupRect.origin.y=visibilityRect.origin.y-visibilityPopupRect.size.height-38;
pollCell.visibilityPopupView.frame=visibilityPopupRect;
} else {
pollCell.dateLabel.frame=dateRect;
pollCell.visibilityButton.frame=visibilityRect;
visibilityPopupRect.origin.y=visibilityRect.origin.y-visibilityPopupRect.size.height;
pollCell.visibilityPopupView.frame=visibilityPopupRect;
}
}
}
}
}
}
return pollCell;
}
else if([info.isSender boolValue ]|| [info.isRequester boolValue]|| [info.isReceiver boolValue] || [info.isProvider boolValue])
{
static NSString *cellIdentifier = @"AppListCell";
IXOutMessageCustomCell *cell = (IXOutMessageCustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"IXOutMessageCustomCell" owner:self options:nil] objectAtIndex:0];
//cell._mAskedButton.hidden=YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.tapButton addTarget:self action:@selector(showPopup:) forControlEvents:UIControlEventTouchUpInside];
}
if (cell.replyview.hidden == NO) {
cell.replyview.hidden = YES;
}
if ([info.isRequester boolValue]) {
NSNumber *count = info.responseCount;
NSInteger value = [count integerValue];
for (int i =0; i<value; i++) {
[self configureCell:cell atIndexPath:indexPath];
}
} else {
[self configureCell:cell atIndexPath:indexPath];
}
[self configureCell:cell atIndexPath:indexPath];
if([info.isSender boolValue] || [info.isRequester boolValue] || [info.isProvider boolValue])
{
CGRect dateFrame=cell.dateLabel.frame;
dateFrame.origin.x=15;
cell.dateLabel.frame=dateFrame;
cell.dateLabel.textAlignment=NSTextAlignmentLeft;
}
else
{
CGRect dateFrame=cell.dateLabel.frame;
dateFrame.origin.x=48;
cell.dateLabel.frame=dateFrame;
cell.dateLabel.textAlignment=NSTextAlignmentCenter;
}
[cell.showTypeButton addTarget:self action:@selector(showTypePopUp_Clicked:) forControlEvents:UIControlEventTouchUpInside];//edited by rsk
return cell;
}
else
{
return nil;
}
}