Note that there are some explanatory texts on larger screens.

plurals
  1. POI am unable to copy my NSMutable array to appDelegate_iPhone array(Universal app)
    primarykey
    data
    text
    <p>Actually I have parsed an XML and store URL's of images as an <code>NSMutableArray</code> object, but I want this array to be used in another <code>ViewController</code> (to give to <code>UIImage</code> in <code>UIImageView</code> to show Images at runtime), so I am trying to <strong>copy that Mutable array</strong> to <code>myAppDelegate_iPhone's NSMutableArray</code>. And I want to <strong>again copy that Appdelegate's array</strong> to my next or other <code>ViewControllers</code> <code>NSMutableArray</code>. </p> <p>so can anyone help me out <strong>pleaseeeeee</strong>? Here is my code :-</p> <p>code:-</p> <pre><code>@class FirstViewController; @interface AppDelegate_iPhone : NSObject &lt;UIApplicationDelegate&gt; { UIWindow *window; FirstViewController *viewController; NSMutableArray *logoArray; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) NSMutableArray *logoArray; @end #import "AppDelegate_iPhone.h" #import "FirstViewController.h" #import "ParsingViewController.h" @implementation AppDelegate_iPhone @synthesize window,logoArray; #pragma mark - #pragma mark Application lifecycle - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. viewController = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil]; viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; NSURL *url = [[NSURL alloc] initWithString:@"http://litofinter.es.milfoil.arvixe.com/displayxml1.aspx"]; NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url]; //Initialize the delegate. ParsingViewController *parser = [[ParsingViewController alloc] init]; //Set delegate [xmlParser setDelegate:parser]; //Start parsing the XML file. BOOL success = [xmlParser parse]; if(success) NSLog(@"No Errors"); else NSLog(@"Error Error Error!!!"); logoArray = [[NSMutableArray alloc]init]; [self.window addSubview:viewController.view]; [self.window makeKeyAndVisible]; return YES; } // dealloc done @end @class Litofinter,AppDelegate_iPhone; @interface ParsingViewController : NSObject&lt;NSXMLParserDelegate&gt; { NSString *myString; NSMutableArray *myMutableArray; Litofinter *obj; NSString *currentElement; AppDelegate_iPhone *appDelegate; } #import "ParsingViewController.h" #import "Litofinter.h" #import "AppDelegate_iPhone.h" @implementation ParsingViewController @synthesize myMutableArray, myString; -(id)init{ if(self == [super init]){ myMutableArray = [[NSMutableArray alloc] init]; } return self; } - (void)parserDidStartDocument:(NSXMLParser *)parser { //myMutableArray = [[NSMutableArray alloc]init]; } // Parsing done here - (void)parserDidEndDocument:(NSXMLParser *)parser { appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate]; //UIApplication *app = [UIApplication sharedApplication]; //appDelegate=app.delegate; appDelegate.logoArray = [[NSMutableArray alloc]initWithArray:myMutableArray]; NSLog(@"appDelegate.logoArray count %d",[appDelegate.logoArray count]); for (Litofinter *lito in appDelegate.logoArray) { NSLog(@"Array Elements :----- %@",lito.cLogo); } } @end #import &lt;UIKit/UIKit.h&gt; @class AppDelegate_iPhone,Litofinter,ParsingViewController; @interface FirstViewController : UIViewController { NSMutableArray *array; //Litofinter *lito; NSString *logoString; AppDelegate_iPhone *appDelegate; ParsingViewController *obj; } @end #import "FirstViewController.h" #import "AppDelegate_iPhone.h" #import "Litofinter.h" #import "ParsingViewController.h" @implementation FirstViewController -(id)init{ if(self == [super init]){ obj = [[ParsingViewController alloc] init]; array = [[NSArray alloc] initWithArray: obj.myMutableArray]; } return self; } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; int x=5,y=10; appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate]; // UIApplication *app = [UIApplication sharedApplication]; // appDelegate=app.delegate; NSLog(@"delegate Array ====== %d",[appDelegate.logoArray count]); NSLog(@"New Array ====== %d",[obj.myMutableArray count]); /* array = [[NSMutableArray alloc]initWithArray:appDelegate.logoArray]; NSLog(@"array at 0 ===== %@",[array objectAtIndex:0]); for (Litofinter *lito1 in obj.myMutableArray) { NSLog(@"Array Elements in Lito1 are :------------- %@",lito1.cLogo); } for (Litofinter *lito2 in array) { NSLog(@"Array Elements in Lito1 are :------------- %@",lito2.cLogo); } */ for (Litofinter *lito in obj.myMutableArray) { //for (int i=0; i&lt;[appDelegate.logoArray count]; i++) { // lito.cLogo = [array objectAtIndex:i]; NSLog(@"%@",lito.cLogo); UIImage *imageFromUrl = [UIImage imageWithContentsOfFile:[NSURL fileURLWithPath:lito.cLogo]]; UIImageView *imgView = [[UIImageView alloc] initWithImage:imageFromUrl]; [imgView setFrame:CGRectMake(x, y, 196, 90)]; [self.view addSubview:imgView]; UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapImage)]; [imgView addGestureRecognizer:tgr]; // [tgr release]; //Do the rest of your operations here, don't forget to release the UIImageView x = x + 200; } } -(void)onTapImage { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message from mAc" message:@"Trail" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil]; [alert show]; } - (void)dealloc { [super dealloc]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload