Code Monkey home page Code Monkey logo

popupwithdatafromxml's Introduction

XMLParser class check xml file on server, download it, parse xml and present alert view with parameters from xml. If user press β€œYES” button in alert view, web link will be open in Safari.

To implement it you must:

  1. Copy PopUpWithDataFromXML folder into your project folder.
  2. In your RootViewController.h include header:
#import "XMLParser.h"
  1. In your RootViewController.h include:
@interface RootViewController : UIViewController <UIAlertViewDelegate,XMLParserDelegate> {
    XMLParser *parser;
NSURL *url;
}
  1. In your RootViewController.m include:
#import "InfoViewController.h"

@implementation RootViewController
#pragma mark - Lazily instantiating 
-(XMLParser *)parser {
    if (!parser) {
        parser = [[XMLParser alloc] init];
        parser.delegate = self;
    }
    return parser;
}

- (void)viewDidLoad {
//start downloading and parsing data from server
    [[self parser] downloadCustomData];
}

#pragma mark - UIAlertView Delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    
    if([title isEqualToString:@"NO"])
    {
        NSLog(@"NO");
    }
    else if([title isEqualToString:@"YES"])
    {
        NSLog(@"YES");
        //Or you can open Safari and show link
        // [[UIApplication sharedApplication] openURL:url];
       
       //create controller and show data
        
        InfoViewController *infoController = [[InfoViewController alloc] initWithURL:url];
        [url release];
        [self.navigationController pushViewController:infoController animated:YES];
        [infoController release];
    } 
}

[[#pragma mark - XMLParser Delegate

-(void)parserDetectNewDataToShow:(NSDictionary *)data {
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[data objectForKey:@"title"] message:[data objectForKey:@"message"] delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES",nil];
    url = [[NSURL alloc] initWithString:[data objectForKey:@"url"]];
    if (alert) {
        [alert show];
    }
    [alert release];
}

@end]]
  1. In InfoViewController.m in viewDidLoad customize your views.
  2. Place your information in TestFile.xml.
  3. Place TestFile.xml on your server.
  4. In XMLParser.m in downloadCustomData method paste link to TestFile.xml file on your server.
  5. Change version key to show alert view once.

popupwithdatafromxml's People

Contributors

yeleleo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.