为什么Splash Screen需要很长时间才能启动

时间:2011-07-13 09:46:30

标签: iphone objective-c

在我的应用中,为什么Splash屏幕需要很长时间才能启动。任何人都请告诉我。

先谢谢:) .h文件代码是:

@interface RootViewController : UITableViewController<NSXMLParserDelegate> {
        UIButton *facebookbutton;
        UIButton *twitterbutton;
        UIButton *youtubebutton;
        UIImageView *backgroundView;
        UIImageView *cellImage;
        UIView *backView;
        UILabel *contactuslabel1;
        UILabel *newslabel1;
        UILabel *dirLabel;
        UILabel *abtLabel;
        UILabel *faqLabel;
        UILabel *evtLabel;
        UIImageView *countImg;
        UILabel *cntLabel;
        UILabel *alrtLabel;
        UIImageView *alrtCountImg;
        UILabel *alrtCountLabel;

        NSURLConnection *xmlConnection;
        NSMutableString *xmlValue;
        NSMutableDictionary *currentItem;
        NSMutableData *responseData;
        NSMutableArray *xmlParseArray;
        NSString *urlString;
        NSString *theXML;
        NSString *alertString;
        NSString *eventString;
        UIAlertView *networkAlert;


@property(nonatomic, retain)UIImageView *cellImage;
@property(nonatomic, retain)UIView *backView;
@property(nonatomic,retain)NSURLConnection *xmlConnection;
@property(nonatomic,retain)NSMutableString *xmlValue;
@property(nonatomic,retain)NSMutableDictionary *currentItem;
@property(nonatomic,retain)NSMutableData *responseData;
@property(nonatomic,retain)NSMutableArray *xmlParseArray;
@property(nonatomic,retain) NSString *urlString;
 ********************************************************************

.m文件代码是

@implementation RootViewController
@synthesize cellImage,backView;
@synthesize responseData,xmlValue,xmlConnection,xmlParseArray,currentItem,urlString;

// Check Network Reachability Connection---------
- (void) showNetWorkAlert {

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    networkAlert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"This app require an internet connection via wifi or cellular network to work." 
                                             delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Retry", nil];

    [networkAlert show];    
    [networkAlert release]; 
}

#pragma mark To Check Network Connection.
- (BOOL) currentNetworkStatus {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    BOOL connected;
    const char *host = "www.apple.com";
    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, host);
    SCNetworkReachabilityFlags flags;
    connected = SCNetworkReachabilityGetFlags(reachability, &flags);
    BOOL isConnected = NO;
    isConnected = connected && (flags & kSCNetworkFlagsReachable) && !(flags & kSCNetworkFlagsConnectionRequired);
    CFRelease(reachability);

    if(!isConnected) {
        // sleep(1);
        [self showNetWorkAlert];
    }
    else
        return isConnected;

    return isConnected;
}



- (void)viewDidLoad
{
    [super viewDidLoad];
    [self currentNetworkStatus];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    self.title = @"Association's Name";

    self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
    self.tableView.separatorColor = [UIColor clearColor];
    self.tableView.userInteractionEnabled=YES;
    self.tableView.scrollEnabled = YES; 
    self.tableView.rowHeight = 49.0;

    facebookbutton=[UIButton buttonWithType:UIButtonTypeCustom];
    facebookbutton.frame = CGRectMake(85, 359, 48, 48);
    [facebookbutton setBackgroundColor:[UIColor clearColor]];
    [facebookbutton setImage:[UIImage imageNamed:@"facebook_icon.png"] forState:UIControlStateNormal];
    [facebookbutton addTarget:self action:@selector(facebookbuttonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:facebookbutton];

    youtubebutton=[UIButton buttonWithType:UIButtonTypeCustom];
    youtubebutton.frame = CGRectMake(133, 359, 48, 48);
    [youtubebutton setBackgroundColor:[UIColor clearColor]];
    [youtubebutton setImage:[UIImage imageNamed:@"youtube.png"] forState:UIControlStateNormal];
    [youtubebutton addTarget:self action:@selector(youtubebuttonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:youtubebutton];

    twitterbutton=[UIButton buttonWithType:UIButtonTypeCustom];
    twitterbutton.frame = CGRectMake(180, 359, 48, 48);
    [twitterbutton setBackgroundColor:[UIColor clearColor]];
    [twitterbutton setImage:[UIImage imageNamed:@"twitter.png"] forState:UIControlStateNormal];
    [twitterbutton addTarget:self action:@selector(twitterbuttonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:twitterbutton];


     self.urlString = @"http://alpha.cfcdi.org/eassociation/web-service/init.xml";

    [self parseData];

//    [self performSelector:@selector(parseData) withObject:self afterDelay:0.1f];

}

-(void)facebookbuttonAction{
    FaceBookViewContoller *faceBookViewContoller = [[FaceBookViewContoller alloc]init];
    [self.navigationController pushViewController:faceBookViewContoller animated:YES];
    [faceBookViewContoller release];
}
-    (void)twitterbuttonAction{

    TwitterViewController *twitterViewController = [[TwitterViewController alloc]init];
    [self.navigationController pushViewController:twitterViewController animated:YES];
    [twitterViewController release];
}
-(void)youtubebuttonAction{

    YouTubeViewController *youTubeViewController = [[YouTubeViewController alloc]init];
    [self.navigationController pushViewController:youTubeViewController animated:YES];
    [youTubeViewController release];
}

//...................Load URL String For Connection................
-(void)parseData
{
    xmlConnection = [[NSURLConnection alloc] 
                     initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", urlString]]] delegate:self];

    if (xmlConnection == nil){
        NSLog(@"Connection Error");
    }
    else{
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        responseData = [[NSMutableData alloc] retain];
        xmlValue = [[NSMutableString alloc] init];
        currentItem = [[NSMutableDictionary alloc] init];       
        xmlParseArray = [[NSMutableArray alloc] init];
    }
}


#pragma mark URLConnection delegate methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [responseData setLength:0];
}    

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    NSLog(@"error :%@",error);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
    theXML = [[NSString alloc] initWithBytes: [responseData mutableBytes] length:[responseData length] encoding:NSUTF8StringEncoding];
    NSLog(@"theXML :%@",theXML);
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:responseData];  
    [parser setDelegate:self];  
    [parser parse];

}
//---------------- NSXML Parser Delegate---------------------------------
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
    if([elementName isEqualToString:@"Init"]){
    }   
    [xmlValue setString:@""];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

    if ([elementName isEqualToString:@"alerts"]) {
        [currentItem setValue:[NSString stringWithString:xmlValue] forKey:elementName];
    }else if ([elementName isEqualToString:@"events"]) {
        [currentItem setValue:[NSString stringWithString:xmlValue] forKey:elementName];
    }else if ([elementName isEqualToString:@"Init"]) {
        [self.xmlParseArray addObject:[NSDictionary dictionaryWithDictionary:currentItem]];
    }   

    NSLog(@"xmlArray is : %@",xmlParseArray);

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    [xmlValue appendString:string];

}


// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
     return 1;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{      
    return 7;



}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    // Configure the cell.
    cellImage = [[UIImageView alloc]initWithFrame:CGRectMake(12,6,303,46)];
    cellImage.backgroundColor = [UIColor clearColor];          
    cellImage.image = [UIImage imageNamed:@"first_cell.png"];
    [cell addSubview:cellImage];
    cell.backgroundColor = [UIColor clearColor];

//    NSLog(@"xmlArray At CellForRowAtIndexPath is : %@",xmlParseArray);





        if(indexPath.row == 0)
        {
            cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;           
            UILabel *aboutlabel = [[UILabel alloc]initWithFrame:CGRectMake(20,12,75,25)];
            aboutlabel.backgroundColor = [UIColor clearColor];
            aboutlabel.text = @"About Us";
            aboutlabel.textAlignment = UITextAlignmentLeft;
            [cell addSubview:aboutlabel];

            [aboutlabel release];


        }
        if(indexPath.row == 1)
        {      
            cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
            UILabel *label11 = [[UILabel alloc]initWithFrame:CGRectMake(20,12,75,25)];
            label11.backgroundColor = [UIColor clearColor];
            label11.text = @"Directory";
            label11.textAlignment = UITextAlignmentLeft;
            [cell addSubview:label11];

            [label11 release];

        }
        if(indexPath.row == 2)
        {
            UILabel *alertlabel = [[UILabel alloc]initWithFrame:CGRectMake(20,13,150,25)];
            alertlabel.backgroundColor = [UIColor clearColor];
            alertlabel.text = @"Events";
            alertlabel.textAlignment = UITextAlignmentLeft;
            [cell addSubview:alertlabel];

            UIImageView *cellImg3 = [[UIImageView alloc]initWithFrame:CGRectMake(265,14,32,23)];
            cellImg3.image = [UIImage imageNamed:@"count_bg.png"];
            cellImg3.backgroundColor = [UIColor clearColor];
            [cell addSubview:cellImg3];

            UILabel *label6 = [[UILabel alloc]initWithFrame:CGRectMake(263,10,36,26)];
            label6.backgroundColor = [UIColor clearColor];
            label6.text =  [[self.xmlParseArray objectAtIndex:1] objectForKey:@"events"];
            label6.textAlignment = UITextAlignmentCenter;
            label6.textColor = [UIColor whiteColor];
            [cell addSubview:label6];

            [alertlabel release];
            [cellImg3 release];

        }


        if(indexPath.row == 3)
        {   
            cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
            UILabel *newslabel = [[UILabel alloc]initWithFrame:CGRectMake(20,13,150,25)];
            newslabel.backgroundColor = [UIColor clearColor];
            newslabel.text = @"News";
            newslabel.textAlignment = UITextAlignmentLeft;
            [cell addSubview:newslabel];

            [newslabel release];

        }

        if(indexPath.row == 4)
        {

            UILabel *eventlabel = [[UILabel alloc]initWithFrame:CGRectMake(20,12,150,25)];
            eventlabel.backgroundColor = [UIColor clearColor];
            eventlabel.text = @"Alerts";
            eventlabel.textAlignment = UITextAlignmentLeft;
            [cell addSubview:eventlabel];

            UIImageView *cellImg4 = [[UIImageView alloc]initWithFrame:CGRectMake(265,14,32,23)];
            cellImg4.image = [UIImage imageNamed:@"count_bg.png"];
            cellImg4.backgroundColor = [UIColor clearColor];
            [cell addSubview:cellImg4];

            UILabel *label5 = [[UILabel alloc]initWithFrame:CGRectMake(263,10,36,26)];
            label5.backgroundColor = [UIColor clearColor];
            label5.text = [[self.xmlParseArray  objectAtIndex:0] objectForKey:@"alerts"]; 
            label5.textAlignment = UITextAlignmentCenter;
            label5.textColor = [UIColor whiteColor];
            [cell addSubview:label5];

            [eventlabel release];
            [cellImg4 release];
            [label5 release];
        }

        if(indexPath.row == 5)
        {
            cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;         
            UILabel *askuslabel = [[UILabel alloc]initWithFrame:CGRectMake(20,14,150,25)];
            askuslabel.backgroundColor = [UIColor clearColor];
            askuslabel.text = @"FAQ / Ask Us";
                askuslabel.textAlignment = UITextAlignmentLeft;
            [cell addSubview:askuslabel];

            [askuslabel release];

        }

        if(indexPath.row == 6)
        {

            cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
            UILabel *contactuslabel = [[UILabel alloc]initWithFrame:CGRectMake(20,14,150,25)];
            contactuslabel.backgroundColor = [UIColor clearColor];
            contactuslabel.text = @"Contact Us";
            contactuslabel.textAlignment = UITextAlignmentLeft;
            [cell addSubview:contactuslabel];

            [contactuslabel release];

        }

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    backView = [[UIView alloc] initWithFrame:CGRectMake(5,6,300,39)];
    backView.backgroundColor = [UIColor lightGrayColor]; // blueColor
    [cell addSubview:backView];
    self.backView.hidden = NO;


    if(indexPath.row == 0){

        abtLabel = [[UILabel alloc]initWithFrame:CGRectMake(20,12,75,25)];
        abtLabel.backgroundColor = [UIColor clearColor];
        abtLabel.text = @"About Us";
        abtLabel.textAlignment = UITextAlignmentLeft;
        [cell addSubview:abtLabel];

        AboutUsViewController *aboutUsViewController = [[AboutUsViewController alloc]init];
        [self.navigationController pushViewController:aboutUsViewController animated:YES];
        [aboutUsViewController release];
        [abtLabel release];

        }

        if(indexPath.row == 1){

            dirLabel = [[UILabel alloc]initWithFrame:CGRectMake(20,12,75,25)];
            dirLabel.backgroundColor = [UIColor clearColor];
            dirLabel.text = @"Directory";
            dirLabel.textAlignment = UITextAlignmentLeft;
            [cell addSubview:dirLabel];

            DirectoryListViewController *directoryListViewController = [[DirectoryListViewController alloc]init];
            [self.navigationController pushViewController:directoryListViewController animated:YES];
            [directoryListViewController release];
            [dirLabel release];
         }

       if(indexPath.row == 2){

           if(![self currentNetworkStatus])
           {
               UIAlertView *eNetAlert = [[UIAlertView alloc]initWithTitle:@"No Internet Connection" message:@"This app require an internet connection via wifi or cellular network to work." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Retry", nil];
               [eNetAlert show];
               [eNetAlert release];
               self.backView.hidden = YES;


           }
               else {
           alrtLabel = [[UILabel alloc]initWithFrame:CGRectMake(20,13,150,25)];
           alrtLabel.backgroundColor = [UIColor clearColor];
           alrtLabel.text = @"Events";
           alrtLabel.textAlignment = UITextAlignmentLeft;
               [cell addSubview:alrtLabel];

           alrtCountImg = [[UIImageView alloc]initWithFrame:CGRectMake(265,14,32,23)];
           alrtCountImg.image = [UIImage imageNamed:@"count_bg.png"];
           alrtCountImg.backgroundColor = [UIColor clearColor];
           [cell addSubview:alrtCountImg];

            alrtCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(263,10,36,26)];
            alrtCountLabel.backgroundColor = [UIColor clearColor];
            alrtCountLabel.text = [[self.xmlParseArray  objectAtIndex:1] objectForKey:@"events"];
            NSLog(@"alrtCountLabel.text : %@",alrtCountLabel.text);
            alrtCountLabel.textAlignment = UITextAlignmentCenter;
            alrtCountLabel.textColor = [UIColor whiteColor];
            [cell addSubview:alrtCountLabel];


           EventViewController *eventViewController = [[EventViewController alloc]init];
           [self.navigationController pushViewController:eventViewController animated:YES];

           [eventViewController release];
           [alrtLabel release];
           [alrtCountImg release];
           [alrtCountLabel release];
           }

        }

        if(indexPath.row == 3)
        {
            newslabel1 = [[UILabel alloc]initWithFrame:CGRectMake(20,13,150,25)];
            newslabel1.backgroundColor = [UIColor clearColor];
            newslabel1.text = @"News";
            newslabel1.textAlignment = UITextAlignmentLeft;
            [cell addSubview:newslabel1];

            NewsViewController *newsViewController = [[NewsViewController alloc]init];
            [self.navigationController pushViewController:newsViewController animated:YES];

            [newsViewController release];
            [newslabel1 release];

        }

        if(indexPath.row == 4){

            if(![self currentNetworkStatus])
            {
                UIAlertView *eNetAlert1 = [[UIAlertView alloc]initWithTitle:@"No Internet Connection" message:@"This app require an internet connection via wifi or cellular network to work." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Retry", nil];
                [eNetAlert1 show];
                [eNetAlert1 release];
                self.backView.hidden = YES;
            }
            else {
            evtLabel = [[UILabel alloc]initWithFrame:CGRectMake(20,12,150,25)];
            evtLabel.backgroundColor = [UIColor clearColor];
            evtLabel.text = @"Alerts";
            evtLabel.textAlignment = UITextAlignmentLeft;
            [cell addSubview:evtLabel];

            countImg = [[UIImageView alloc]initWithFrame:CGRectMake(265,14,32,23)];
            countImg.image = [UIImage imageNamed:@"count_bg.png"];
            countImg.backgroundColor = [UIColor clearColor];
            [cell addSubview:countImg];

            cntLabel = [[UILabel alloc]initWithFrame:CGRectMake(263,10,36,26)];
            cntLabel.backgroundColor = [UIColor clearColor];
            cntLabel.text = [[self.xmlParseArray  objectAtIndex:0] objectForKey:@"alerts"];
            NSLog(@"cntLabel.text : %@",cntLabel.text);
            cntLabel.textAlignment = UITextAlignmentCenter;
            cntLabel.textColor = [UIColor whiteColor];
            [cell addSubview:cntLabel];

            AlertViewController *alertViewController = [[AlertViewController alloc]init];
            [self.navigationController pushViewController:alertViewController animated:YES];

            [alertViewController release];

            [evtLabel release];
            [countImg release];
            [cntLabel release];
         }

        }


        if(indexPath.row == 5){

            faqLabel = [[UILabel alloc]initWithFrame:CGRectMake(20,14,150,25)];
            faqLabel.backgroundColor = [UIColor clearColor];
            faqLabel.text = @"FAQ / Ask Us";
            faqLabel.textAlignment = UITextAlignmentLeft;
            [cell addSubview:faqLabel];

            AskOneViewController *askOneViewController = [[AskOneViewController alloc]init];
            [self.navigationController pushViewController:askOneViewController animated:YES];
            [askOneViewController release];
            [faqLabel release];


        }            

       if(indexPath.row == 6){

           cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
           contactuslabel1 = [[UILabel alloc]initWithFrame:CGRectMake(20,14,150,25)];
           contactuslabel1.backgroundColor = [UIColor clearColor];
           contactuslabel1.text = @"Contact Us";
           contactuslabel1.textAlignment = UITextAlignmentLeft;
           [cell addSubview:contactuslabel1];

           ContactUsViewController *contactUsViewController = [[ContactUsViewController alloc]init];
            [self.navigationController pushViewController:contactUsViewController animated:YES];
            [contactUsViewController release];
                [contactuslabel1 release];
        }


}

/*- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}*/

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

}

- (void)viewDidAppear:(BOOL)animated
{

    [super viewDidAppear:animated];
    self.cellImage.hidden = NO;
    self.backView.hidden = YES;
    contactuslabel1.hidden = YES;
    newslabel1.hidden = YES;
    dirLabel.hidden = YES;
    abtLabel.hidden = YES;
    faqLabel.hidden = YES;
    evtLabel.hidden =YES;
    countImg.hidden =YES;
    cntLabel.hidden = YES;
//    alrtLabel.hidden = YES;
    alrtCountImg.hidden =YES;
    alrtCountLabel.hidden = YES;


}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload
{
    [super viewDidUnload];

    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}

- (void)dealloc
{
    [facebookbutton release];
    [twitterbutton release];
    [youtubebutton release];
    [super dealloc];
}

@end




-(void)parseData;

@end

1 个答案:

答案 0 :(得分:3)

这不是启动画面需要这么长时间,而是加载并初始化您的应用程序(直到它到达您的应用程序最终可以显示其第一个视图的位置)。

相关问题