0

1つの大きな問題があります。ページングを使用して uitable ビューを実装しましたが、行 700 に達するとアプリケーションがクラッシュし、iPad が再起動することもあります。だから私はあらゆることを試しましたが、解決策が得られません。これは私のコードです。

#pragma mark - Table View

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
 return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (dataArray.count<[self.allRecordCount intValue])
    {
        return dataArray.count+1;
    }
 return dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 if (dataArray.count<[self.allRecordCount intValue])
    {
        if (indexPath.row < dataArray.count) {
           return [self dataCellForIndexPath:indexPath tableview:tableView];
    } else {
        return [self loadingCell];
    }
}else{
    return [self dataCellForIndexPath:indexPath tableview:tableView];
}

}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (cell.tag == kLoadingCellTag) {

    [self fillDataArray];
}
}
      - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {

     return 150;
    }
#pragma mark PAGING_LOGIC
-(void)fillDataArray
 {
self.strStartPoint=[NSString stringWithFormat:@"%d",[dataArray count]];
self.strPageSize=[NSString stringWithFormat:@"%d",kPageSize];
NSMutableArray *temp=[manager returnCallArray:self.strStartPoint NoofRecord:self.strPageSize];
for (Call *obj in temp)
{
    [dataArray addObject:obj];
}
[temp release];
[tbl reloadData];
}

- (UITableViewCell *)loadingCell {
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                                reuseIdentifier:nil] autorelease];

    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]
                                                  initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activityIndicator.frame=CGRectMake(480.5f,52.5f , 45, 45);


    [cell addSubview:activityIndicator];
    [activityIndicator release];

    [activityIndicator startAnimating];

     cell.tag = kLoadingCellTag;

 return cell;
}


- (UITableViewCell *)dataCellForIndexPath:(NSIndexPath *)indexPath tableview:(UITableView *)table
{

 NSString *CellIdentifier = [NSString stringWithFormat:@"%d %d",indexPath.section,indexPath.row];
 UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];
if(table.tag == 0){

    //cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UILabel *lblCall;UILabel *lblCallText;UILabel *lblAirComment;UILabel *lblCustomerTxt;UILabel *lblProximityTxt;

    UILabel *lblNoOfMachineTxt;
    UILabel *lblCallReceiveTxt;
    UILabel *lblCallDueTxt;
if (cell==nil) {
 Call *temp = [dataArray objectAtIndex:indexPath.row];
 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                       reuseIdentifier:CellIdentifier] autorelease];
 lblCall = [[UILabel alloc]initWithFrame:CGRectMake(20,setY,220,20)];
        lblCall.backgroundColor = [UIColor clearColor];
        lblCall.text = @"Call Priority/Type/Status";
        [cell.contentView addSubview:lblCall];
        [lblCall release];
 lblCallText = [[UILabel alloc]initWithFrame:CGRectMake(220,setY,270,20)];
        lblCallText.backgroundColor = [UIColor clearColor];


        lblCallText.tag = indexPath.row+100;
 [cell.contentView addSubview:lblCallText];
        [lblCallText release]; 
 lbl_strstatusChangeReason = [[UILabel alloc] init];/
 lbl_strstatusChangeReason.frame=CGRectMake(20,setY,800, labelSize5.height);
        lbl_strstatusChangeReason.backgroundColor = [UIColor clearColor];
        lbl_strstatusChangeReason.text = str_changeStatusReasoon;
        lbl_strstatusChangeReason.tag = indexPath.row + 200000;
        lbl_strstatusChangeReason.numberOfLines = 0;
        lbl_strstatusChangeReason.lineBreakMode = UILineBreakModeWordWrap;
        lbl_strstatusChangeReason.textColor = [UIColor redColor];
        [cell.contentView addSubview:lbl_strstatusChangeReason];
 }
 return cell;
 }

これは、セルを埋めるために使用する私の NSObject です。

#import <Foundation/Foundation.h>

 @interface Call : NSObject {

NSString *strType;
NSString *strTypePriority;
NSString *strCustomer;
NSString *strProximity;
 NSString *strETADateTime;

NSString *str480;
NSString *strAirComment;
NSString *strProblemDesc;
NSString *strNumberOfMachine;
NSString *strCallReceived;
NSString *strCallDue;
NSString *strAssignedTech;
  NSString *strAssignedTechName;
NSString *strDefaultTech;
  NSString *strDefaultTechName;
NSString *strDispatchedBy;
}
 @property(nonatomic,retain)NSString *strDispatchedToTechInterval;
 @property(nonatomic,retain)NSString *strDispatchedToBranchInterval;

 @property(nonatomic,retain)NSString *strDispatchToTechnicianDate;
 @property(nonatomic,retain)NSString *strDispatchToTechnicianTime;
 @property(nonatomic,retain)NSString *strDispatchToTechnicianFrom;
 @property(nonatomic,retain)NSString *strDispatchToTechnicianBy;

 @property(nonatomic,retain)NSString *strCallClosedDateAndTimeSorting;
 @property(nonatomic,retain)NSString *strCallClosedDateAndTime;
 @property(nonatomic,retain)NSString *strCallClosedDate;
 @property(nonatomic,retain)NSString *strCallClosedTime;
 @property(nonatomic,retain)NSString *strtotalAmount;
 @property(nonatomic,retain)NSString *strtotalPartAmount;
 @property(nonatomic,retain)NSString *strtotalChargeAmount;
 @property(nonatomic,retain)NSString *strOriginatingFacility;
 @property(nonatomic,retain)NSString *str_RecordVersionNumber;
 @property(nonatomic,retain)NSString *str_CustomerLatitude;
 @property(nonatomic,retain)NSString *str_CustomerLongitude;
 @property(nonatomic,retain)NSString *strDiscount;
 @property(nonatomic,retain)NSString *str_HdrComment1; 
 @property(nonatomic,retain)NSString *str_PrioritySortValue;
 @property(nonatomic,retain)NSString *str_StatusChangeReason;
 @property(nonatomic,retain)NSString *str_OnSiteDate;
 @property(nonatomic,retain)NSString *str_Address;
 @property(nonatomic,retain)NSString *str_Address1;
 @property(nonatomic,retain)NSString *str_Address2;
 @property(nonatomic,retain)NSString *str_City;
 @property(nonatomic,retain)NSString *str_State;
 @property(nonatomic,retain)NSString *str_Zip;
 @property(nonatomic,retain)NSString *strStatus;
 @property(nonatomic,retain)NSString *strTypePriority;
 @property(nonatomic,retain)NSString *strCustomer;
 @property(nonatomic,retain)NSString *strProximity;
 @property(nonatomic,retain)NSString *str480;
 @property(nonatomic,retain)NSString *strAirComment;
 @property(nonatomic,retain)NSString *strProblemDesc;
 @property(nonatomic,retain)NSString *strNumberOfMachine;
 @property(nonatomic,retain)NSString *strCallReceived;
 @property(nonatomic,retain)NSString *strCallDue;
 @property(nonatomic,retain)NSString *strAssignedTech;
 @property(nonatomic,retain)NSString *strDefaultTech;
 @property(nonatomic,retain)NSString *strDispatchedBy;
 @end

 #import "Call.h"

 @implementation Call


 @synthesize strStatus;
 @synthesize strTypePriority;
 @synthesize strCustomer;
 @synthesize strProximity;
 @synthesize str480;
 @synthesize strAirComment;
 @synthesize strProblemDesc;
 @synthesize strNumberOfMachine;
 @synthesize strCallReceived;
 @synthesize strCallDue;
 @synthesize strAssignedTech;
 @synthesize strDefaultTech;
 @synthesize strDispatchedBy;

 @synthesize strCallNumber;
 @synthesize strHoldCall;
 @synthesize strOpenCall;
 @synthesize strLoactionId;
 @synthesize strCustomerName;
 @synthesize strContactName;
 @synthesize strPhoneNo;
 @synthesize strFirsMachine;
 @synthesize strMachineDone;
 @synthesize strDispatchedToBranch;
 @synthesize strDispatchedToTech;
 @synthesize strServiceDue;
 @synthesize strCallComment;
 @synthesize strDiscount;
 - (void)dealloc {

[strStatus release];
[strTypePriority release];
[strCustomer release];
[strProximity release];
[str480 release];
[strAirComment release];
[strProblemDesc release];
[strNumberOfMachine release];
[strCallReceived release];
[strCallDue release];
[strAssignedTech release];
[strDefaultTech release];
[strDispatchedBy release];
[strCallNumber release];
[strHoldCall release];
[strOpenCall release];
[strLoactionId release];
[strCustomerName release];
[strContactName release];
[strPhoneNo release];
[strFirsMachine release];
[strMachineDone release];
[strDispatchedToBranch release];
[strDispatchedToTech release];
[strServiceDue release];
[strCallComment release];
[strDiscount release];
[str_StatusChangeReason release];
 [super dealloc];
 }

これは、ページング用の配列を埋めるために使用している私の方法です。

 -(NSMutableArray *)returnCallArray:(NSString *)startPoint NoofRecord:(NSString *)noOfRecord
 {
[self initiateFMDB];
    NSMutableArray *aryCallFilterData=[[NSMutableArray alloc]init];
  //  NSMutableArray *finalArrayCall=[[NSMutableArray alloc]init];
@try {
    if(![db open]){
        NSLog(@"Could not open  DB");
    }
    else{
           resultset = [db executeQuery:[NSString stringWithFormat:@"select Call_HDR.*,Problem.Machine,Problem.ServiceStatusFlag,AssignTech.RepName AS AssignTechName,DefaultTech.RepName AS DefaultTechName,Problem.ProblemDescription AS ProblemDescription,Problem.SLAHours AS SLAHours,ARComment.CustARComments As CustARComments,SLAResponseCode.SLAResponse As SLAResponse from CALL_HDR LEFT  JOIN Branch_Reps as AssignTech ON CALL_HDR.RepID = AssignTech.RepID LEFT  JOIN Branch_Reps as DefaultTech ON CALL_HDR.AssignedServiceRep = DefaultTech.RepID LEFT  JOIN CALL_MACHINE as Problem ON CALL_HDR.CallNumber||'*001' = Problem.CallNumberWSeqnbr LEFT  JOIN Customers as ARComment ON CALL_HDR.LocationID = ARComment.LocationID LEFT  JOIN NA_Data as SLAResponseCode ON CALL_HDR.CustomerTypeCode = SLAResponseCode.NationalAccountCode where CALL_HDR.CallStatus IN ('%@','%@')  LIMIT  %@,%@ ",STATUS_CLOSED,STATUS_CANCELLED,startPoint,noOfRecord]];
    }
}
@catch (NSException * e) {
    NSLog(@"Exception error for selectFromItemPhoto is %@",[e reason]);
}
if (!resultset) {
    NSLog(@"no result set fechted");
  }
  while ([resultset next]) {
     NSString *strCallPrioritySortValue = [resultset stringForColumn:@"PrioritySortValue"];
     NSString *strCallPriority = [resultset stringForColumn:@"CallPriority"];
     NSString *strCallType = [resultset stringForColumn:@"CallType"];
     NSString *strCallStatus = [resultset stringForColumn:@"CallStatus"];
     NSString *strCustomerName = [resultset stringForColumn:@"CustomerName"];
     NSString *strAdd1 = [resultset stringForColumn:@"Address1"];
     NSString *strAdd2 = [resultset stringForColumn:@"Address2"];
     NSString *strCity = [resultset stringForColumn:@"City"];
     NSString *strState = [resultset stringForColumn:@"State"];
     NSString *strZip = [resultset stringForColumn:@"Zip"];
     NSString *strCustomer=@"";
    ObjModel.strStsChgByRep=strStatusChgByRep;
    ObjModel.strCustomer = strCustomer;
    ObjModel.strStatus = strCallStatus;
    ObjModel.strHoldCall =strHoldCode;
    ObjModel.strProximity = @"";
    ObjModel.f_proximity = 0.0f;
    ObjModel.str480 = strStr480;
    ObjModel.strProblemDesc = strProbleDesc;
    ObjModel.strNumberOfMachine =strNumberOfMachine;
    ObjModel.strCallReceived = strCallReceive;
    ObjModel.strCallDue = strCallDue;
    ObjModel.strAssignedTech =  strAssignedTech;
    ObjModel.strDefaultTech = strDefaultTech;
    ObjModel.strDispatchedBy = strDispatchedBy;
    ObjModel.strCallNumber =  strCallNumber;
    ObjModel.n_CallNumber = [strCallNumber intValue];
    ObjModel.strLoactionId = strLoactionId;
    ObjModel.strContactName = strContactName;
    ObjModel.strCustomerName = strCustomerName;
    ObjModel.strPhoneNo = strPhoneNo;
    ObjModel.strDiscount = strDisct;
    ObjModel.strAirComment = strAirComment;
    ObjModel.strAssigntechName = strAssignedTechBy;
    ObjModel.strRepId = strRepId;
    ObjModel.str_Address1 = strAdd;
    ObjModel.str_StatusChangeReason = strStatusChangeReason;
    [aryCallFilterData addObject:ObjModel];
    [ObjModel release];
   }
 return aryCallFilterData;
}

だから私のコードを見直して、クラッシュを解決できるように何かを提案してください。

これはクラッシュログです:

Received memory warning.
2013-06-24 04:59:26.168 MFSS_PAGING_FACEBOOK[874:907] <FMDatabase: 0x2d8aa130> executeQuery: select Call_HDR.*,Problem.Machine,Problem.ServiceStatusFlag,AssignTech.RepName AS AssignTechName,DefaultTech.RepName AS DefaultTechName,Problem.ProblemDescription AS ProblemDescription,Problem.SLAHours AS SLAHours,ARComment.CustARComments As CustARComments,SLAResponseCode.SLAResponse As SLAResponse from CALL_HDR LEFT  JOIN Branch_Reps as AssignTech ON CALL_HDR.RepID = AssignTech.RepID LEFT  JOIN Branch_Reps as DefaultTech ON CALL_HDR.AssignedServiceRep = DefaultTech.RepID LEFT  JOIN CALL_MACHINE as Problem ON CALL_HDR.CallNumber||'*001' = Problem.CallNumberWSeqnbr LEFT  JOIN Customers as ARComment ON CALL_HDR.LocationID = ARComment.LocationID LEFT  JOIN NA_Data as SLAResponseCode ON CALL_HDR.CustomerTypeCode = SLAResponseCode.NationalAccountCode where CALL_HDR.CallStatus IN ('8','0')  LIMIT  700,100

ありがとう

4

2 に答える 2

1

細胞を再利用する必要があります。非常に多くの UITableViewCells がメモリにロードされており、メモリ警告の後にクラッシュします。

セル識別子 (インデックス + 行) は、700 行のデータをロードするときに 700 個のセルを作成します。セル識別子は、画面に表示されるセルの数に対して一意である必要があり、それを超えてはなりません。最良の方法は、他の簡単で非ループのセル識別子を使用できることです。そのため、細胞はより効率的に再利用されます。

同じ UITableViewCell を使用してみますが、表示する情報に一致するラベルと detailLabels を変更してください。

于 2013-06-24T09:16:12.290 に答える
0

注目すべき点の 1 つは、コードでの dequeueReusableCellWithIdentifier の使用です。セルセクションと行を識別子として使用しているため、データ項目ごとに新しいセルを作成していると言えます。これには理由がありますか?セルが視覚的に同じ (それぞれのデータのみが異なる) 場合は、これを変更して、dequeueReusableCell 識別子が各セルで同じになるようにします。これにより、OS はセルのメモリをより効率的に管理できるようになります。

于 2013-06-24T09:17:17.480 に答える