2013-08-09 2 views
1
에 지역을 할당 할 수 없습니다 내가 UIPickerView의 행이 방법이 내 충돌을 여러 통화 후이 방법 -

오류 : 아이폰 OS

-(void)setScheduleStartDate:(NSString *)dateStr 
{ 
    [scheduleDatesArray removeAllObjects]; 
    NSDateFormatter* df = [[NSDateFormatter alloc] init]; 
    df.dateFormat = @"d MMMM yyyy"; 
    scheduleStartDate = [df dateFromString:dateStr]; 

    /******* getting array of schedule dates  ***********/ 

    NSDate* scheduleEndDate = [scheduleStartDate dateByAddingTimeInterval:60*60*24*28*6]; // add six month (of 28 days) in schedule start date 
    double endMS = [scheduleEndDate timeIntervalSinceDate:scheduleStartDate]; 

    for (double i =0; i < endMS; i = (i + 60*60*24*14)) { 

     [scheduleDatesArray addObject:[NSNumber numberWithDouble:i]]; 
    } 
} 

를 호출하여 선택받을 때마다 변경 가능한 배열에 객체를 추가 해요

오류 (I 배열에 객체를 추가 해요 경우) 루프에 malloc_error_break에서 내 응용 프로그램의 중단을 중단 점을 설정하여 메시지

malloc: *** mmap(size=627101696) failed (error code=12) 
*** error: can't allocate region 
*** set a breakpoint in malloc_error_break to debug 

. 그러나 나는 문제를 찾을 수 없습니다, 나는 동일한 문제에 대한 구글 검색했지만 여전히 행운을 찾지 못했습니다.

내가 뭘 잘못하고 있는지 도울 수 있습니까?

+0

'scheduleDatesArray'가'NSMutableArray'라고 가정합니까? –

+0

그리고 ARC를 사용하고 있습니까? –

+0

예 NSMutableArray이며 scheduleDatesArray = [[NSMutableArray alloc] initWithCapacity : 0];으로 할당됩니다. 그리고 나는 ARC를 사용하고 있습니다 – Bharat

답변

2

월이 28 일 또는 심지어 a minute is 60 seconds이라는 일부 가정을 토대로 날짜 계산을하지 말아야합니다.

대신 dateByAddingTimeInterval:의 사용 NSCalendardateByAddingComponents:toDate:options:

NSDateComponents *sixMonthComponents = [[NSDateComponents alloc] init]; 
sixMonthComponents.month = 6; 

NSCalendar *currentCalendar = [NSCalendar currentCalendar]; 
NSDate* scheduleEndDate = [currentCalendar dateByAddingComponents:sixMonthComponents toDate:scheduleStartDate options:0]; 

편집 : 내가 이해가 정의한대로, 당신은 모든에 대한 배열 ~ 십사일 (반 달에 시간 간격을 추가 할에서 한달 28 일). 보다 강력한하기 위해, 나는 이런 식으로 뭔가 할 것 (안 테스트를하지만, 작업을해야, 알려주세요) :

// We increment i with the total interval between the two dates (endMS) divided by 12 (6 months * 2 times per month) 
for (double i = 0; i < endMS; i += (endMS/12) { 
    [scheduleDatesArray addObject:@(i)]; 
} 

사이드 참고 : [NSNumber numberWithDouble:i]can be written @(i).

+0

예 배열에 시간 간격을 추가하고 있지만 14는 사용자 선택에 따라 1, 4, 7, 14, 28 일로 변합니다. – Bharat

+0

나는 당신의 제안을 시도했지만 여전히 운이 없다. – Bharat

+0

좋아, 나는 for 루프에서 나는 iar와 iar의 값을 높이기 위해 ivar (14는 단지 예이다)를 사용했다. ivar은 -1에 할당되고 loop는 무한하다. (나의 실수) .. 나는 내 코드를 더욱 신뢰할 수있게하기 위해 답을 수락합니다. – Bharat