Passing Image from popoverview to viewcontroller - Objective-C - objective-c

Can I pass an Image from a popoverview to the controller that brings the popoverview forward? Can I pass the image with a delegate or do I have to put it in NSData to transport it?
I am having struggles with it, I already tried a thousand tutorials but I can't get it working, so my question is:
Is it possible to pass images from popoverviews to viewcontrollers?
And, if yes: what is the easiest way to understand and do this?

Related

NSImageView setImage causing NSView not correctly initialized

I'm writing a networking program which sends an image from an iPhone to a Mac. I have the connection going fine, and passing data alright, but my problem is when I have the image sent over I try to display it and get the following warning:
NSImageView(0x101321fd0) - NSView not correctly initialized. Did you
forget to call super?
Here is the code, it's the "setImage" command throwing the error.
This is my first major venture into Objective-C, I'm worried I messed up something with the xib but I can't be sure.
imageView = [NSImageView alloc];
[imageView setImage:theImage];
NSLog(#"Should be able to see image now..");
If this is too vague for a direct answer then any tips, references or tutorials you can guide me to would be very welcome.
Thanks for your time.
You forget to init the imageView.
imageView = [[NSImageView alloc] initWithFrame:someFrame]

Can I target a delegate to a "specific" instance of a ViewController, to get it's data?

How can I do this?
I have ViewController 1, and ViewController 2.
ViewController 1 defines a protocol and ViewController 2 conforms to it.
I set ViewController 2 has a delegate and invoke a method in ViewController 1. This method runs fine. And send confirmation back to my ViewController 2.
I can exchange data between them, but I'm trying to figure out a way, to get data from a particular instance of ViewController 1, to ViewController 2.
Because when I'm using my delegate, to run a method in ViewController 1 it's not going for that particular instance that I'm interested in.
Is there a way I can resolve this?
Can I set my delegate, a delegate of a particular instance so I can get it's state? Is this possible? And if so, how?
In other words, can I target a specific instance with my delegate?
--
p.s. if I try to get data of a property ruled by ViewController 1, it come has nil (I think this is because I'm not targeting a particular instance)! One way I can resolve it, is have a method that reads "already saved data". But I would be replicating code, and instantiating new objects with data that is already available in previous ViewControllers.
Any help is most appreciated. Thank you in advance!
Nuno
edit:
SetupTableViewController *delegate = [[SetupTableViewController alloc] init];
[delegate setDelegate:self];
Every property I try to get from this point on forward, is nil. How can I target this to a particular instance of my previous ViewController? I do not want to instantiate a new SetupViewController. What I really need is to access an existing instance of my SetupViewController.
The question is really vague and you should probably post some code to better explain what you're trying to achieve.
"I can exchange data between them, but I'm trying to figure out a
way, to get data from a particular instance of ViewController 1, to
ViewController 2."
Well when you do myViewController1Instance.delegate = self; , any delegate call that you make will only be sent from myViewController1Instance object to ViewController2, not from the other instances of ViewController1 class.
instead of using delegation the way you are trying to do, which is a little bit akward, try using notifications instead.. when an instance knows that it needs to send something it throws a notification that it is caught by the view controller 2.
why do you have more than one instance of vc1 on the screen? can you give more info on what you are trying to achieve?
Add (UIViewController*)sender to your protocol messages.
On receipt of the message, check the sender, if it isn't the one you're interested in, just return.
I have to agree with Sorin though, you're probably better using notification.
Problems like these can often be fixed with architectural improvements. Always good to step back and think if the data is in the correct place.

Creating UIWebview programmatically and using it to do a couple of things then destroy it?

Is it possible to create a hidden UIWebView programmatically and then release it(destroy it completely deallocating all of it's memory) when I have used it? If so, could you give some tips. Thanks!
It seems odd that you want to use a hidden UIWebView object for some task when the main purpose of an UIWebView object is to present the html content. The answer to your question is yes. You can create them and remove them programmatically just like any other view as #Nil has mentioned but it seems your main purpose behind this is to get the content. If that's so, you have many other ways you can get that content without having to create a UIWebView object. You can use NSString's initWithContentsOfURL:encoding:error: method to get the contents of the url into a string which you can parse and use. NSData has a similar method. However to use these you will have to perform them in the background otherwise they will block the main thread. The most obvious and better way would be to use NSURLConnection or its popular counterpart ASIHTTPRequest.
Yes, you can create and destroy a uiwebview as any other uiview.

How co call methods of EAGLView from ES1Renderer?

Using the standard OpenGL ES iPad pattern we get such 'structure'. I've read some about delegating, protocols, but still got no direct answer for this particular purpose. Please enlighten me.
Why would I need this? Well all the action goes on in ES1Renderer and I want to [EAGLView setUserInteractionEnabled:true]; for example, which gives me:
'EAGLView' may not respond to
'+setUserInteractionEnabled:'
You're sending a message to a class, not an instance. You'd need an object of type EAGLview to send the setUserInteractionEnabled: message to.
Like:
EAGLView *myView;
[myView setUserInteractionEnabled:true];

Changing an NSImage in XCode - this line of code not working

I am having a problem that is eating me alive. I really hope I am just missing something small here. It appears to be a rather "n00b" issue.
I have a blank NSImageView that I want to display a picture when a button is pressed — simple as that.
Here is my line of coding
NSBundle *mb = [NSBundle mainBundle];
NSString *fp = [mb pathForResource:#"tiles" ofType:#"PNG"];
NSImage *image = [[NSImage alloc] initWithContentsOfFile:fp];
if ( [image isValid] ) {
[selection setImage:image];
[selection setImageScaling:NSScaleProportionally];
}
Whereas,
tiles.PNG is a resource in my bundle
and if [image isValid] is satisfied, because I've inserted dummy code into the clause and had that work
selection is defined in my header file as follows
IBOutlet NSImageView *selection;
It is also linked up to the application delegate in IB.
I have a feeling I might not be linking it properly?
WHy wouldn't the image display? If anyone can see an error - or provide me with working code - I would be soooooo thankful
Brian
It's not a linking issue—your app wouldn't even launch (assuming it even links successfully) if you'd failed to link against Cocoa or AppKit.
More probably, either you haven't connected the outlet to your image view in your nib, or you haven't loaded the nib yet. The way to check this would be to NSLog the value of the imageView pointer, using the %p formatter.
I had a similar issue where my view wasn't displaying, and it turned out that the view was hidden. This was a setting in the view properties in Interface Builder. Just a punt, but give it a go.
You need to use the debugger and see what's going on as it runs. Is fp nil? Is image nil? Is selection nil? The debugger is your friend.
did you remember to send -setNeedsDisplay to the NSImageView after you set the image?