2013-06-24 2 views
0

하나의 주요 문제가 있습니다. 내가 페이징으로 uitable보기를 구현했지만 내가 행 700 응용 프로그램에 충돌 때로는 ipad를 다시 시작 충돌. 그래서 모든 것을 시도했지만 해결책을 얻지 못하고 있습니다. 이것은 내 코드입니다.600 행을로드 한 후 UITableview 페이징 크래시 응용 프로그램

#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 *[email protected]""; 
    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 

감사

+0

아니요, 사용자는 합리적으로 먼저 디버깅 할 책임이 있습니다. 인터넷에 수백 줄의 코드를 던지면 안됩니다. 문제가있는 곳에서 운동하십시오. 상황에 영향을 미치는지 확인하기 위해 줄 주석 처리를 시작하십시오. – borrrden

+0

메모리 경고가 있습니까? –

+0

borrrden, 나는 많은 시간이 코드를 debuged 내가 분명히 테이블 응용 프로그램에서 700 행의 스크롤 후 충돌 언급. 그리고이 코드를 게시에 대한 내 관심사는 코드에 어떤 문제가 있거나 그것이 내 nsobject 또는 내 데이터 가져 오기 방법에 문자열이 많이 찍은 영향을 미칠 수 있습니다 잘못된 방법입니다. 어떤 사람이 코드를보고 있으면 코드에서 잘못된 것이 무엇인지 쉽게 알아낼 수 있습니다. 어쨌든 당신의 제안에 감사드립니다. – Nikh1414

답변

1

당신은 당신의 세포를 재사용해야

이 충돌 로그입니다. 너무 많은 UITableViewCells 메모리에로드 된 및 메모리 경고 후 충돌합니다.

데이터의 700 행을로드 할 때 셀 식별자 (index + row)는 700만큼의 셀을 만듭니다. 셀 식별자는 화면에 표시된 셀 수에 대해 고유해야합니다. 가장 좋은 점은 다른 쉽고 반복적이지 않은 셀 식별자를 가질 수 있다는 것입니다. 그래서 세포는보다 효율적으로 재사용됩니다.

동일한 UITableViewCell을 사용하려고하지만 표시 할 정보와 일치하는 레이블 및 detailLabels를 변경하십시오.

+0

예 karim, 흐름 위에 스택에 코드를 게시 한 후 변경 사항을 적용하여 이제는 1000 개의 행을 쉽게로드 할 수 있지만 이제 각 행의 높이가 변경되고 그 행이 서로 겹쳐서 문제가 발생합니다. 내가 생각하고 그 CGSize constraintSize5 = CGSizeMake (800, MAXFLOAT); CGSize labelSize5 = [str_changeStatusReasoon sizeWithFont : [UIFont systemFontOfSize : 17] constrainedToSize : constraintSize5 lineBreakMode : UILineBreakModeWordWrap]; 완벽한 높이를 제공하지 못하므로 레이블의 동적 높이를 계산하는 다른 방법이 있습니다. 감사. – Nikh1414

+0

텍스트 높이 (레이블)를 계산할 때 UITableView 대리자의 heightForRowAtIndexPath 대리자 메서드를 재정의해야합니다. 그 방법에서 높이를 계산해야합니다. 나는 그 때 그것이 좋을 것이라는 점을 희망한다. – karim

0

살펴볼 가치가있는 한 가지는 코드에서 dequeueReusableCellWithIdentifier 사용입니다. 내가 셀 섹션과 행을 식별자로 사용하고 있기 때문에 각 데이터 항목에 대해 새 셀을 생성한다고 말할 수 있습니다. 이것에 대한 이유가 있습니까? 셀이 시각적으로 같으면 (각 셀의 데이터 만 다름) dequeueReusableCell 식별자가 각 셀에 동일하도록이 값을 변경하십시오. 이를 통해 OS는 셀의 메모리를보다 효율적으로 관리 할 수 ​​있습니다.

관련 문제