Re: Checking to see if there is a second screen present
Re: Checking to see if there is a second screen present
- Subject: Re: Checking to see if there is a second screen present
- From: leenoori <email@hidden>
- Date: Fri, 10 Nov 2006 19:01:22 +0100
El 10/11/2006, a las 18:28, Adam Radestock escribió:
How do I check to see if there is a second screen without throwing
an exception if there isn't?
Currently my code is as follows: -
NSScreen* myQCScreen = [[NSScreen screens] objectAtIndex:1];
You need to read the NSScreen documentation, particularly for the
"screens" method.
1. First up, you should enclose this in a @try/@catch block because,
as the documentation notes, the method can raise a
NSWindowServerCommunicationException
2. You can't make assumptions about the number of elements in the
array returned by [NSScreen screens]; in the line above you are
assuming that it has at least 2 elements (at index 0 and index 1),
and if it has less then you're going to provoke an NSRangeException
(again, see the NSArray documentation).
Various ways to write this but your code at a minimum needs to
include this kind of logic (or similar)
NSArray *screens = nil;
@try
{
screens = [NSScreen screens];
}
@catch (id e)
{
NSLog(@"+[NSScreen screens] raised an exception");
}
if (screens && ([screens count] > 1))
{
// do something with the second screen...
NSScreen *myQCScreen = [screens objectAtIndex:1]; // etc
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden