0
지금은이 코드를 사용하고

:Three20의 TTLauncherView 사용 : 필요 분할과 도움에있는 NSArray에있는 NSMutableArray에서 나머지 개체를 추가 오브젝티브 C

- (void)loadLauncher:(NSMutableArray *)categoriesArray { 
    _launcherView = [[TTLauncherView alloc] initWithFrame:self.view.bounds]; 
    _launcherView.columnCount = 3; 

    // Number of pages in your launcherView. 
    NSMutableArray *pages = [[NSMutableArray alloc] initWithCapacity:2]; 

    int numberOfObjects = [categoriesArray count]; 

    // The launcherItems in each page, calculate automatically the number of objects available for the launcher. 
    NSMutableArray *launcherItems = [[NSMutableArray alloc] initWithCapacity:1]; 

    // The counter to identify if the number of objects exceeds the, 
    // capacity of a launcher page of 9. 
    int j = 1; 

    for (int i = 0; i < numberOfObjects; i++){ 
     if (j > 9){ 
      // Add the current launcherItems array to the pages. 
      [pages addObject:launcherItems]; 

      // Initialise new launcher items. 
      launcherItems = [[NSMutableArray alloc] initWithCapacity:1]; 

      // Start the counter again. 
      j = 1; 
     } else { 
      int i = 0; 
      for (Category *c in categoriesArray) { 
       NSString *categoryImage = [[NSString stringWithFormat:@"bundle://category_%@_icon.png", [Utility removeSpecialCharacters:@"&'- " withString:c.categoryName]] lowercaseString]; 
       NSLog(@" - %@", categoryImage); 
       TTLauncherItem *launcherItem = [[[TTLauncherItem alloc] initWithTitle:c.categoryName 
                       image:categoryImage 
                        URL:[NSString stringWithFormat:@"%d", i] 
                      canDelete:NO] autorelease]; 

       [launcherItems addObject:launcherItem];   

       i++; 
      } 
     } 

     j++; 
    } 

    // Add the current launcherItems to the pages. 
    [pages addObject:launcherItems]; 
    [launcherItems release]; 

    _launcherView.pages = pages; 

    [self.view addSubview:_launcherView]; 
} 

오래된 방법

내가 사용하고 TTLauncherView 컨트롤러부터 http://three20.info.

Three20은 App Store에서 인기있는 응용 프로그램의 인기를 강화하는 Objective-C 클래스 모음입니다. 그것은 당신에게 개발 시간을 절약 할 수있는 매우 유용한 기능을 제공합니다.

라이브러리는 모듈 식으로 제작되므로 라이브러리의 요소를 선택적으로 프로젝트에 통합 할 수 있습니다. 또한 드롭 인 XML 및 JSON 구문 분석과 응용 프로그램 테마를위한 CSS 스타일 시트 지원을 비롯한 확장 기능 세트가 늘어나고 있습니다.

나는 다음을 수행하는 방법을 아주 확실하지 않다 : 내 arrayOfLauncherItems이 16 개체가 있는지 여부를

  1. 확인; 및
  2. 개체가 16 개 이상이면 나머지 나머지 개체를 _launcherView.pages에 추가하십시오. 그래서 총 32 개의 객체가 있다고 가정하면 나머지 16 개의 객체 중 다른 배열을 만들어 _launcherView.pagesNSArray에 추가 할 수 있기를 원합니다.

이는 TTLauncherView 컨트롤러의 작동 방법의 일 예이다 :

TTLauncherView *_launcherView = [[TTLauncherView alloc] initWithFrame:self.view.bounds]; 

NSMutableArray *arrayOfLauncherItems = [[NSMutableArray alloc] init]; 
//add TTLauncherItem objects to arrayOfLauncherItems. 

_launcherView.pages = [NSArray arrayWithObjects:arrayOfLauncherItems, nil]; 

arrayOfLauncherItems 나머지 TTLauncherItem 개체 (두 번째, 세 번째 페이지에이어야하며 즉, 16 개 이상의 물체를 포함 할 수있다 얼마나 많은 총 물체가 있는지에 따라).

다음과 같이하면 arrayOfLauncherItems에서 동일한 16 개의 개체가 추가됩니다. 즉, 두 번째 페이지가 있음을 의미합니다. 즉, arrayOfLauncherItems에 32 개 이상의 개체가 있으면 기본적으로 달성하고 싶은 페이지입니다.

_launcherView.pages = [NSArray arrayWithObjects:arrayOfLauncherItems, arrayOfLauncherItems, nil]; 

답변

1

다음 코드를 사용하고 싶습니다. 기본 아이디어는 사용 가능한 개체의 수를 기반으로 페이지 수를 자동으로 계산하는 것입니다. 각 페이지에 3x3 = 9 개의 실행 프로그램 항목이 있다고 가정합니다. 이런 방식으로, 9보다 작거나 큰 오브젝트의 총 수를 걱정할 필요가 없습니다. 원하는 경우이 값을 상수에 넣을 수 있습니다.

NSMutableArray *pages = [NSMutableArray array]; 
NSMutableArray *launcherItems = [NSMutableArray array]; 

//the counter to identify if the number of objects exceeds the 
//capacity of a launcher page of 9 
int j = 1; 
for (int i = 0; i < numberOfObjects; i++){ 

    TTLauncherItem *launcherItem = [[[TTLauncherItem alloc] initWithTitle: @"a title" 
                    image: @"bundle://abc.png" 
                     URL: @"someUrlPath" 
                   canDelete:TRUE] autorelease]; 
    [launcherItems addObject:launcherItem];   

    j++; 

    if (j> 9){ 
     //add the current launcherItems to the pages 
     [pages addObject:launcherItems]; 

     //initialize new launcher items 
     launcherItems = [NSMutableArray array]; 
     //start again the counter 
     j = 1; 
    }  
} 
//add the current launcherItems to the pages 
[pages addObject:launcherItems]; 

_launcherView.pages = pages; 
+0

원래 질문을 업데이트하고 코드를 사용했습니다. 하지만 두 페이지 모두에서 같은 항목을 가져 오지는 않습니다. 또한 페이지 수에 대해 initWithCapacity를 2로 설정하십시오. 총 항목 수에 2보다 많은 페이지가있는 경우 어떻게 제어 할 수 있습니까? – fuzz

+0

이 버그로 저를 도울 수 있습니까? 그러나 지금 당신의 코드를 사용하고 있습니다. columnCount를 3으로 사용하고 있는데, 페이지 당 총 9 개의 카테고리를 제공합니다. 문제는 10 번째 항목이 표시되지 않는 것입니다. 단순히 10 번째 항목을 건너 뛰고 2 번째 페이지로 이동하지만 11 번째 항목 항목부터 시작합니다. 이걸 내게 주시겠습니까? – fuzz

+0

안녕하세요 풀비오, 지연에 대해 유감스럽게 생각하며 귀하의 의견을 알지 못했습니다. 작동하는 경우 업데이트 된 코드를 확인하십시오. –

1

1) [myArray count]을 사용하면 배열의 항목 수를 얻을 수 있습니다.

2) for 루프를 사용

NSMutableArray *overflow = [NSMutableArray array]; 
NSMutableArray *sixteen = [NSMutableArray array]; 
for (int i = 16; i < [arrayOfLauncherItems count]; i++) 
{ 
    [overflow addObject:[arrayOfLauncherItems objectAtIndex:i]]; 
} 
for (int i = 0; i < 16; i++) 
{ 
    [sixteen addObject:[arrayOfLauncherItems objectAtIndex:i]]; 
} 

_launcherView.pages = [NSArray arrayWithObjects:sixteen, overflow, nil]; 

배열이 끝날 때까지 인덱스 (16)에서 개체를 추가하고 다른 배열에 추가 할 루프의 첫 번째. 두 번째 배열은 원래 배열의 처음 16 개 요소의 배열로 끝납니다.

+0

위의 코드는 내가 필요로하는 방식으로 작동하지 않습니다. 그것은 실제로 그것이 있어야하는 것보다 더 많은 항목입니다. 실제로 페이지 당 16 이상을 표시하지만 실제로는 두 번째 페이지에도 일부 표시됩니다.아마 내가 제대로 구현하지 않을거야. 나는 arrayOfLauncherItems가 16보다 큰지 그리고 당신의 코드를 ELSE로 사용하는지 확인하고 있습니다. _launcherView.pages = [NSArray arrayWithObjects : arrayOfLauncherItems, nil]; – fuzz

+0

나는 당신이하려고하는 것을 이해한다고 생각합니다. 편집 한 코드 샘플을 참조하십시오. –

+0

나는 두 개의 어레이를 교체하는 것을 잊어 버렸다고 생각합니다. myArray 및 arrayOfLauncherItems가 현재 무엇인지 확실하지 않습니다. 그들은 같은 의미일까요? 또한 오버플로로는 아무 것도하지 않습니다. – fuzz