2012-08-05 30 views
0

在我的TTLauncherView實現中,只加載第一頁。爲什麼?在TTLauncherView中加載更多頁面

我有47個項目在數組中,47個項目div 9個項目,我應該有6個頁面。

感謝您的幫助。

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {  


NSMutableString *jsonString = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
NSDictionary *results = [jsonString JSONValue]; 

NSArray *photos = [[results objectForKey:@"photosets"] objectForKey:@"photoset"]; 

launcherView = [[TTLauncherView alloc] initWithFrame:self.view.bounds]; 
launcherView.backgroundColor = [UIColor whiteColor]; 
launcherView.delegate = self; 
launcherView.columnCount = 3; 

launcherView.persistenceMode = TTLauncherPersistenceModeNone; 
NSMutableArray *itemArray = [[NSMutableArray alloc] init]; 
for (NSDictionary *photo in photos) 
{ 

    NSString *iconURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_s.jpg", 
    [photo objectForKey:@"farm"], [photo objectForKey:@"server"], [photo objectForKey:@"primary"], [photo objectForKey:@"secret"]]; 


    NSDictionary *title = [photo objectForKey:@"title"]; 
    NSString *itemTitle = [title objectForKey:@"_content"]; 
    TTLauncherItem *itemMenu = [[[TTLauncherItem alloc] initWithTitle:itemTitle 
                   image:iconURLString 
                    URL:nil 
                  canDelete:NO] autorelease]; 

    [itemArray addObject:itemMenu];  

} 

launcherView.pages = [NSArray arrayWithObject: itemArray]; 
[self.view addSubview:launcherView]; 

} 

回答

0

我記得,TTLauncherView不會將TTLauncherItem自動分解成頁面。你需要一個數組數組。第一個數組中的所有啓動器項目都將位於第一個頁面上,第二個數組中的所有啓動器項目都將位於第二個頁面等等。使用它已經很長時間了,但我認爲這就是有效。

+0

感謝@Darren的暗示!沒錯,現在正在工作。 – EversonNovka 2012-08-06 13:53:31

0

我修改後的代碼與@Darren

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {  

NSMutableString *jsonString = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];  
NSDictionary *results = [jsonString JSONValue];  
NSArray *photos = [[results objectForKey:@"photosets"] objectForKey:@"photoset"]; 
NSMutableArray *itemArray = [[NSMutableArray alloc] init]; 
NSMutableArray *pageArray = [[NSMutableArray alloc] init]; 
NSNumber *countPage = [[NSNumber alloc] initWithInt:0]; 

for (NSDictionary *photo in photos) 
{ 

    NSString *iconURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_s.jpg", 
           [photo objectForKey:@"farm"], [photo objectForKey:@"server"], [photo objectForKey:@"primary"], [photo objectForKey:@"secret"]]; 

    NSString *photoCount = [photo objectForKey:@"photos"]; 
    NSDictionary *title = [photo objectForKey:@"title"]; 
    NSString *itemTitle = [title objectForKey:@"_content"]; 
    TTLauncherItem *itemMenu = [[[TTLauncherItem alloc] initWithTitle:itemTitle 
                   image:iconURLString 
                    URL:nil 
                  canDelete:NO] autorelease]; 
    itemMenu.badgeValue = photoCount; 

    [itemArray addObject:itemMenu]; 
    int value = [countPage intValue]; 
    countPage = [NSNumber numberWithInt:value + 1]; 
    if (countPage == [NSNumber numberWithInt:9]){ 
     countPage = [NSNumber numberWithInt:0]; 
     [pageArray addObject:itemArray]; 
     itemArray = [[NSMutableArray alloc] init]; 


    } 

} 
[pageArray addObject:itemArray]; 

launcherView = [[TTLauncherView alloc] initWithFrame:self.view.bounds]; 
launcherView.backgroundColor = [UIColor blackColor]; 
launcherView.delegate = self; 
launcherView.columnCount = 3;  
launcherView.persistenceMode = TTLauncherPersistenceModeNone;  
launcherView.pages = pageArray;  
[self.view addSubview:launcherView];  

}