Re: binding relationship to checkbox

2011-03-07 Thread Amy Gibbs

Hi,

My application has a tab view as the main view (it might look dated  
but I can take it straight from the library and it works)


In one tab I have a table view that holds the 'master' category list.  
Here I can add/remove categories.


In another tab I have my products list. There is a tableview that  
lists the products, and then various other items displaying other  
related data, an image etc. In this tab I have got another  tableview  
that currently has a column for the category name and a checkbox  
column. I want to list all the categories that exist in this  
tableview, and select and deselect the checkboxes to create/break the  
relationship(s) between the selected product and the categories.


Am I along the right lines?

Thanks

Amy

On 6 Mar 2011, at 7:49PM, Jerry Krinock wrote:



On 2011 Mar 05, at 08:20, Amy Heavey wrote:

This sounds to me like something that should be doable with the  
'magic' of bindings


Well, bindings should certainly be involved, but there is more to it  
than that.  The most important is the view that will display your  
checkbox column.  Assuming that the user can add and delete  
'categories', this view will need to grow or shrink and/or scroll  
with the number of objects it contains, and it would be nice to  
avoid writing that code.  I would study these options:


(a) an NSTableView in source list style.
(b) an NSCollectionView
(c) Last resort, a custom view that you code yourself, containing an  
array of checkboxes


Then, the 'categories' in your data model should interface to this  
view via an array controller, and that's where you'll use bindings.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/home%40willowtreecrafts.co.uk

This email sent to h...@willowtreecrafts.co.uk


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Non-showstopping sheets

2011-03-07 Thread Jonathan Taylor
Hi all,

I have another UI type question where I am not sure how best to achieve what I 
want. I have a (non-modal) window in which the user interacts with external 
peripherals. Under certain circumstances (such as the peripheral not being 
turned on) it is not possible to send commands to the device. I thought that a 
window-modal sheet might be a neat way of representing that:
www.dur.ac.uk/j.m.taylor/sheet.png

However, this sort of use of a sheet, window-modal in the sense that it 
prevents interaction with that window, but non-showstopping in the sense that 
it shouldn't prevent closing the parent window or quitting, seems to be hard. I 
have found some mention of these issues in the archives and elsewhere, and as 
far as I can tell:
- sheets are not really designed to work this way
- it is possible to allow quitting, for example manually closing the sheets 
from within -terminate.
- it seems to be impossible to keep the close buttons enabled on the underlying 
window (apparently the underlying window is no longer first responder... 
although true, that in itself should not preclude the close button from working 
unless I'm missing something).

So - is there any way of keeping the close button operational, and/or can 
anybody suggest a more appropriate way of achieving the sort of interface 
effect I'm after here? I thought the sheet mechanism was a rather apt way of 
doing what I want, but it is evidently not a use that has been foreseen in the 
design...

Cheers
Jonny___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Non-showstopping sheets

2011-03-07 Thread Graham Cox

On 07/03/2011, at 11:47 PM, Jonathan Taylor wrote:

 Hi all,
 
 I have another UI type question where I am not sure how best to achieve what 
 I want. I have a (non-modal) window in which the user interacts with external 
 peripherals. Under certain circumstances (such as the peripheral not being 
 turned on) it is not possible to send commands to the device. I thought that 
 a window-modal sheet might be a neat way of representing that:
 www.dur.ac.uk/j.m.taylor/sheet.png
 
 However, this sort of use of a sheet, window-modal in the sense that it 
 prevents interaction with that window, but non-showstopping in the sense that 
 it shouldn't prevent closing the parent window or quitting, seems to be hard. 
 I have found some mention of these issues in the archives and elsewhere, and 
 as far as I can tell:
 - sheets are not really designed to work this way
 - it is possible to allow quitting, for example manually closing the sheets 
 from within -terminate.
 - it seems to be impossible to keep the close buttons enabled on the 
 underlying window (apparently the underlying window is no longer first 
 responder... although true, that in itself should not preclude the close 
 button from working unless I'm missing something).
 
 So - is there any way of keeping the close button operational, and/or can 
 anybody suggest a more appropriate way of achieving the sort of interface 
 effect I'm after here? I thought the sheet mechanism was a rather apt way of 
 doing what I want, but it is evidently not a use that has been foreseen in 
 the design...


I'd say you're trying to fit a round peg in a square hole, and attempting to 
subvert the sheet behaviour isn't going to be fruitful for you or your users.

Instead why not open a hidden section in the window itself that displays the 
operational aspects of what's happening - or why even make it hidden? -  so you 
have your input parameters in the upper section and the operational 'results' 
(perhaps including the progress bar, cancel button, error or progress message, 
and what-have-you) in the lower section. K.I.S.S.

--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Non-showstopping sheets

2011-03-07 Thread Jonathan Taylor
On 7 Mar 2011, at 13:45, Graham Cox wrote:

 I have another UI type question where I am not sure how best to achieve what 
 I want. I have a (non-modal) window in which the user interacts with 
 external peripherals. Under certain circumstances (such as the peripheral 
 not being turned on) it is not possible to send commands to the device. I 
 thought that a window-modal sheet might be a neat way of representing that:
 www.dur.ac.uk/j.m.taylor/sheet.png
 
 However, this sort of use of a sheet, window-modal in the sense that it 
 prevents interaction with that window, but non-showstopping in the sense 
 that it shouldn't prevent closing the parent window or quitting, seems to be 
 hard. I have found some mention of these issues in the archives and 
 elsewhere, and as far as I can tell:
 - sheets are not really designed to work this way
 - it is possible to allow quitting, for example manually closing the sheets 
 from within -terminate.
 - it seems to be impossible to keep the close buttons enabled on the 
 underlying window (apparently the underlying window is no longer first 
 responder... although true, that in itself should not preclude the close 
 button from working unless I'm missing something).
 
 So - is there any way of keeping the close button operational, and/or can 
 anybody suggest a more appropriate way of achieving the sort of interface 
 effect I'm after here? I thought the sheet mechanism was a rather apt way of 
 doing what I want, but it is evidently not a use that has been foreseen in 
 the design...
 
 
 I'd say you're trying to fit a round peg in a square hole, and attempting to 
 subvert the sheet behaviour isn't going to be fruitful for you or your users.
It seems that's the case, though I felt this was *exactly* what a sheet should 
be for (there is a problem that needs to be rectified before you can interact 
further with this window - it's just that in this case no harm will come from 
choosing to ignore the problem by closing the window).

 Instead why not open a hidden section in the window itself that displays the 
 operational aspects of what's happening - or why even make it hidden? -  so 
 you have your input parameters in the upper section and the operational 
 'results' (perhaps including the progress bar, cancel button, error or 
 progress message, and what-have-you) in the lower section. K.I.S.S.
Looks like I will probably end up doing 
that...___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: XML Namespace Definitions on Non-Root Elements

2011-03-07 Thread Heath Borders
That worked!

I actually changed it to:

nodesForXPath:@/root/*[name() = \example:foo\]

Thanks!

-Heath Borders
heath.bord...@gmail.com
Twitter: heathborders
http://heath-tech.blogspot.com



On Sat, Mar 5, 2011 at 2:27 PM, Matt Neuburg m...@tidbits.com wrote:
 On Fri, 04 Mar 2011 14:25:06 -0600, Heath Borders heath.bord...@gmail.com 
 said:
I'm trying to parse a document with a namespace declared on a non-root 
element:

rootexample:foo xmlns:example=http://example.com/foo;This is an
exemplary foo!/example:foo/root

I can read this xml into an NSXMLDocument just fine, but the following
XPath query on root returns a non-nil, but empty NSArray:

NSXMLNode *rootNode = ...// create my root node somehow
NSArray *exampleFooElements = [rootNode
nodesForXPath:@/root/example:foo error:nil];
// exampleFooElements != nil  [exampleFooElements count] == 0

However, if I add the namespace declaration to the root element,
everything is fine:

root xmlns:example=http://example.com/foo;example:fooThis is an
exemplary foo!/example:foo/root

NSXMLNode *rootNode = ...// create my root node somehow
NSArray *exampleFooElements = [rootNode
nodesForXPath:@/root/example:foo error:nil];
// exampleFooElements != nil  [exampleFooElements count] == 1

I can do this change programmatically, but I'd rather not have to
modify the document.  This namespace usage should be legal.  Am I
doing something wrong?

 It's no use just saying example:; you have to have a way to tell it what 
 example: *is* - i.e. you have to bind the namespace - and you don't have a 
 way to do that from here. One option is to bypass the namespace altogether:

  nodesForXPath:@//*[local-name()='foo']

 m.


 --
 matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
 A fool + a tool + an autorelease pool = cool!
 Programming iOS 4!
 http://www.apeth.net/matt/default.html#iosbook
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: binding relationship to checkbox

2011-03-07 Thread Jerry Krinock

On 2011 Mar 07, at 00:58, Amy Gibbs wrote:

 I have got a … tableview that currently has a … checkbox column. I want to 
 list all the categories that exist in this tableview, and select and deselect 
 the checkboxes to create/break the relationship(s) between the selected 
 product and the categories.
 
 Am I along the right lines?

That seems pretty weird.  I would think that one would check or uncheck the 
box, not select or deselect the checkbox, which is in fact an NSButtonCell.  
Checking or unchecking the box could create/break the categories; that would be 
along the right lines.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: binding relationship to checkbox

2011-03-07 Thread Amy Gibbs
Sorry, that's what I meant, I would check and uncheck the checkboxes  
to create/break the relationships,


sorry, my fault for describing it incorrectly.

I still can't work out how I could bind the checkboxes to create this  
action?


Thanks

On 7 Mar 2011, at 4:49PM, Jerry Krinock wrote:



On 2011 Mar 07, at 00:58, Amy Gibbs wrote:

I have got a … tableview that currently has a … checkbox column. I  
want to list all the categories that exist in this tableview, and  
select and deselect the checkboxes to create/break the  
relationship(s) between the selected product and the categories.


Am I along the right lines?


That seems pretty weird.  I would think that one would check or  
uncheck the box, not select or deselect the checkbox, which is in  
fact an NSButtonCell.  Checking or unchecking the box could create/ 
break the categories; that would be along the right lines.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/home%40willowtreecrafts.co.uk

This email sent to h...@willowtreecrafts.co.uk


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Setting a delegate on a UITextField

2011-03-07 Thread Jon Sigman
On Sat, 05 Mar 2011 11:22:46 -0800 Matt Neuburg wrote:
 One possible approach on iOS is to implement textFieldShouldEndEditing, and 
return NO and put up an alert if there's a problem. Another is just to make 
the 
change yourself in textFieldDidEndEditing. See the section entitled 
Validating 
Entered Text (along with the preceding section) in the Managing Text Fields 
and Text Views chapter of the Text, Web, and Editing Programming Guide for 
iOS. 

That looks like a good fit. But is there some trick in 
getting textFieldShouldEndEditing invoked? I have also 
a textFieldDidBeginEditing and a textFieldDidEndEditing method; they get 
invoked 
when 
the user touches the Return key on the keypad, but textFieldShouldEndEditing 
does not.


  
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: XML Namespace Definitions on Non-Root Elements

2011-03-07 Thread Matt Neuburg
Very cool, but I do suggest you file a bug. Apple's XPath interface falls short 
with regard to namespaces. Contrast, for example, Nokogiri which lets you pass 
namespace info into an XPath query, or Microsoft with its XML Namespace Manager 
class. In other words, XPath does know about namespaces, but Apple gives you no 
direct way to tap into this part of its knowledge - a node knows about 
namespace nodes attached to *it*, and supplies these implicitly for any XPath 
queries performed on it (as you discovered) but that's all. This is just wrong. 
Your example is an excellent case in point. m.

On Mon, 07 Mar 2011 09:40:38 -0600, Heath Borders heath.bord...@gmail.com 
said:
That worked!

I actually changed it to:

nodesForXPath:@/root/*[name() = \example:foo\]

Thanks!

-Heath Borders
heath.bord...@gmail.com
Twitter: heathborders
http://heath-tech.blogspot.com



On Sat, Mar 5, 2011 at 2:27 PM, Matt Neuburg m...@tidbits.com wrote:
 On Fri, 04 Mar 2011 14:25:06 -0600, Heath Borders heath.bord...@gmail.com 
 said:
I'm trying to parse a document with a namespace declared on a non-root 
element:

rootexample:foo xmlns:example=http://example.com/foo;This is an
exemplary foo!/example:foo/root

I can read this xml into an NSXMLDocument just fine, but the following
XPath query on root returns a non-nil, but empty NSArray:

NSXMLNode *rootNode = ...// create my root node somehow
NSArray *exampleFooElements = [rootNode
nodesForXPath:@/root/example:foo error:nil];
// exampleFooElements != nil  [exampleFooElements count] == 0

However, if I add the namespace declaration to the root element,
everything is fine:

root xmlns:example=http://example.com/foo;example:fooThis is an
exemplary foo!/example:foo/root

NSXMLNode *rootNode = ...// create my root node somehow
NSArray *exampleFooElements = [rootNode
nodesForXPath:@/root/example:foo error:nil];
// exampleFooElements != nil  [exampleFooElements count] == 1

I can do this change programmatically, but I'd rather not have to
modify the document. Â This namespace usage should be legal. Â Am I
doing something wrong?

 It's no use just saying example:; you have to have a way to tell it what 
 example: *is* - i.e. you have to bind the namespace - and you don't have a 
 way to do that from here. One option is to bypass the namespace altogether:

  nodesForXPath:@//*[local-name()='foo']


--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: binding relationship to checkbox

2011-03-07 Thread Jerry Krinock

On 2011 Mar 07, at 08:55, Amy Gibbs wrote:

 I still can't work out how I could bind the checkboxes

As I said earlier, think: array controller.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Setting a delegate on a UITextField

2011-03-07 Thread Matt Neuburg
On Mon, 07 Mar 2011 09:02:36 -0800 (PST), Jon Sigman rf_...@yahoo.com said:
On Sat, 05 Mar 2011 11:22:46 -0800 Matt Neuburg wrote:
 One possible approach on iOS is to implement textFieldShouldEndEditing, and 
return NO and put up an alert if there's a problem. Another is just to make 
the 
change yourself in textFieldDidEndEditing. See the section entitled 
Validating 
Entered Text (along with the preceding section) in the Managing Text Fields 
and Text Views chapter of the Text, Web, and Editing Programming Guide for 
iOS. 

That looks like a good fit. But is there some trick in 
getting textFieldShouldEndEditing invoked? I have also 
a textFieldDidBeginEditing and a textFieldDidEndEditing method; they get 
invoked 
when 
the user touches the Return key on the keypad, but textFieldShouldEndEditing 
does not.

This has nothing to do with the Return key on the keypad - it has to do with 
the text field resigning its first responder status. The Return key invokes 
textFieldShouldReturn: and does *not* automatically resign first responder 
(unless you've implemented Did End on Exit). As usual, I suggest you make a 
teeny little test project, completely clean, consisting of just a text field 
and its delegate, so as to prove to yourself that textFieldShouldEndEditing: is 
in fact called. m.

--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Proper way to construct an Attribute NSXMLNode so that its prefix is included in its XMLString

2011-03-07 Thread Heath Borders
I have the following NSXMLDocument:

document xmlns=http://example.com/document;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
/document

I want to add an xsi:schemaLocation to the document so that I can validate it.

The documentation says:

attributeWithName:URI:stringValue:
Returns an NSXMLNode object representing an attribute node with a
given qualified name and string.

+ (id)attributeWithName:(NSString *)name URI:(NSString *)URI
stringValue:(NSString *)value
Parameters
name
A string that is the name of an attribute.
URI
A URI (Universal Resource Identifier) that qualifies name.
value
A string that is the value of the attribute.
Return Value
An NSXMLNode object of kind NSXMLAttributeKind or nil if the object
couldn't be created.

Discussion
For example, in the attribute “bst:id=`12345’”, “bst” is the name
qualifier (derived from the URI), “id” is the attribute name, and
“12345” is the attribute value.

Thus, I do the following:

NSXMLElement rootXmlElement = ...
NSXMLNode *schemaLocationAttributeXmlNode =
  [NSXMLNode attributeWithName:@schemaLocation URI:@xsi
stringValue:@http://example.com/document document.xsd];

[rootXmlElement addAttribute:schemaLocationAttributeXmlNode];

However, this yields the following xml:

document xmlns=http://example.com/document;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
schemaLocation=@http://example.com/document document.xsd
/document

Notice that there should be an xsi prefix on the schemaLocation attribute.

and if I call try to get the attribute from the rootXmlElement, I get nothing:

[rootXmlElement attributeForLocalName:@schemaLocation
URI:@http://www.w3.org/2001/XMLSchema-instance;] == nil


Since this didn't work, I tried using the namespace URI instead of the
prefix when creating the attribute:

NSXMLElement rootXmlElement = ...
NSXMLNode *schemaLocationAttributeXmlNode =
  [NSXMLNode attributeWithName:@schemaLocation
URI:@http://www.w3.org/2001/XMLSchema-instance;
stringValue:@http://example.com/document document.xsd];

[rootXmlElement addAttribute:schemaLocationAttributeXmlNode];

This still yielded bad xml:

document xmlns=http://example.com/document;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
schemaLocation=@http://example.com/document document.xsd
/document

However, this time I can at least get the attribute from my rootXmlElement:

[rootXmlElement attributeForLocalName:@schemaLocation
URI:@http://www.w3.org/2001/XMLSchema-instance;] != nil // closer!


So, now, I tried specifying the prefix in the attribute name when
creating the attribute:

NSXMLElement rootXmlElement = ...
NSXMLNode *schemaLocationAttributeXmlNode =
  [NSXMLNode attributeWithName:@xsi:schemaLocation
URI:@http://www.w3.org/2001/XMLSchema-instance;
stringValue:@http://example.com/document document.xsd];

[rootXmlElement addAttribute:schemaLocationAttributeXmlNode];

Success!  I got good xml:

document xmlns=http://example.com/document;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xsi:schemaLocation=@http://example.com/document document.xsd
/document

This doesn't seem consistent with the documentation.  Am I hacking here?

Thanks!

-Heath Borders
heath.bord...@gmail.com
Twitter: heathborders
http://heath-tech.blogspot.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Setting a delegate on a UITextField

2011-03-07 Thread Jon Sigman
On Mon, March 7, 2011 9:30:05 AM Matt Neuburg wrote:

  The Return key invokes textFieldShouldReturn: and does *not* automatically 
resign first responder ...

Ah! That is the part I had been overlooking. textFieldShouldReturn is the 
perfect place to validate the input.

However, now that I've implemented it, textFieldShouldReturn gets called twice 
immediately when the Return key gets pressed on the keypad, not sure why...
Thanks!



  
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTableView: which delegate after a drag operation?

2011-03-07 Thread Corbin Dunn

On Mar 5, 2011, at 2:03 AM, Ulf Dunkel wrote:

 Hi Scott.
 
 1) Which delegate can I use to inform table view B to update and reload 
 its data when I have dragged an item inside table view A?
 
 If you’re adding it to the object array, you can easily do the update 
 notification then.
 
 [..] what do you mean here with the object array”?
 
 If you’re adding the dragged data to your target table, that’s a good time 
 to provide some notification that it needs to be updated.
 
 I only allow rows in NSTableView A to be moved inside A, or rows in 
 NSTableView B to be moved inside B. But when a row in A has been moved, I 
 want B to load and show updated data.
 
 I really don't know which notification or delegate to use for this.
 
 Can you give me a notification example, please?
 

You have to send your own notification, and respond to it.

corbin


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Setting a delegate on a UITextField

2011-03-07 Thread Matt Neuburg

On Mar 7, 2011, at 9:54 AM, Jon Sigman wrote:

 On Mon, March 7, 2011 9:30:05 AM Matt Neuburg wrote:
 
   The Return key invokes textFieldShouldReturn: and does *not* 
  automatically resign first responder ...
 
 Ah! That is the part I had been overlooking. textFieldShouldReturn is the 
 perfect place to validate the input.
 
 However, now that I've implemented it, textFieldShouldReturn gets called 
 twice immediately when the Return key gets pressed on the keypad, not sure 
 why...
 Thanks!
 

Once again I repeat my advice - start with a totally clean project with nothing 
but a text field and its delegate and watch the delegate messages. Keep it 
*simple* when exploring the framework. You will see that what you're saying is 
false. The sequence will be:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(@%@, NSStringFromSelector(_cmd));
[textField resignFirstResponder];
return YES;
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
NSLog(@%@, NSStringFromSelector(_cmd));
return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
NSLog(@%@, NSStringFromSelector(_cmd));
}

2011-03-07 11:02:00.934 Crud[7945:207] textFieldShouldReturn:
2011-03-07 11:02:00.936 Crud[7945:207] textFieldShouldEndEditing:
2011-03-07 11:02:00.938 Crud[7945:207] textFieldDidEndEditing:

Now add your validation.

I really can't advise using textFieldShouldReturn: for validation, because 
there are many *other* ways in which a text field might resign first responder, 
and then you'd miss out on your validation test. It is best to adopt habits 
that work in general, with the intent of the framework, rather than just going 
with something that happens to seem to work okay in one limited case. m.

--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
Programming iOS 4! http://www.apeth.net/matt/default.html#iosbook
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Memory used by a UIImage?

2011-03-07 Thread David Duncan
On Mar 4, 2011, at 8:17 PM, Rick Mann wrote:

 Unfortunately, if I create the image from a PNG, it's possible iOS stores it 
 compressed, and only decompresses when rendering. I'd like to know how much 
 it's using at any given moment.


If you create the UIImage with the withContentsOfFile APIs, then we'll 
reference the file for image data when necessary and may or may not be loaded 
into memory (generally it won't be). If you use the withData APIs, then the 
compressed data is always in memory. Using the withCGImage APIs will depend 
on how you created the CGImage itself.

But if you are trying to figure out your memory usage, it is better to use the 
VM Tracker instrument (part of the Allocations template). You'll have to turn 
on automatic sampling or press the sample button yourself to get data, but 
watching the Dirty Size statistic is what you are interested in here.
--
David Duncan

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


easy way to store table-like data

2011-03-07 Thread Martin Batholdy
Hi,


what is the easiest way to store data and retrieve it in an sql-like-fashion?

I have informations of the form:

name: ...
type: ...
nr of clicks: ...

etc.

and I would like to present it in tableviews (so it should be sortable etc.)

I am familiar with sql ... and this seems pretty straightforward to have a 
sqlite-table where user input of this form gets written in etc.


Is that possible? Perhaps with plists?
What would you suggest?



I would be really thankful for any 
advice!___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: easy way to store table-like data

2011-03-07 Thread Wim Lewis
Well, sqlite3 is available on the system (and is used by a lot of Apple code, 
so hopefully it won't be removed in the near future); you could simply use 
that, if that API is what you're most familiar with.

However, unless you have a pretty large data set, sqlite is probably overkill 
and it'd be easier to use a plist. I would start with an NSArray of 
NSDictionaries, and then if it makes the code cleaner replace the 
NSDictionaries with custom objects containing the fields you're interested in 
and whatever other methods logically belong there.

NSArrayController can do sorting and filtering of these objects for you for 
presentation in the table view; if NSArrayController doesn't do what you need 
then it's easy enough to sort and filter them yourself and then implement the 
NSTableView data source methods. Take a look at the NSArrayController and 
bindings API documentation--- if bindings do what you need, they're really 
quick and convenient.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSMapTable options

2011-03-07 Thread Quincey Morris
Could someone confirm for me that if I want a NSMapTable object with weak 
pointers to both keys and values, and that doesn't copy keys or values, the 
appropriate options are:

[NSMapTable mapTableWithKeyOptions: (NSMapTableZeroingWeakMemory | 
NSMapTableObjectPointerPersonality) options 
valueOptions: (NSMapTableZeroingWeakMemory | 
NSMapTableObjectPointerPersonality)]

Or is [NSMapTable mapTableWithWeakToWeakObjects] sufficient? The documentation 
doesn't say whether this is modeled after a dictionary (copies keys) or not.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: easy way to store table-like data

2011-03-07 Thread Martin Batholdy
Hi,

thanks for the reply.

Is it also possible to filter the entries of an NSDictionary like in SQL?

for example I have a key type and different entries.

Is it possible to get an Array of all elements where type is equal to 
website (or something like that)?



On 07.03.2011, at 21:05, Wim Lewis wrote:

 Well, sqlite3 is available on the system (and is used by a lot of Apple code, 
 so hopefully it won't be removed in the near future); you could simply use 
 that, if that API is what you're most familiar with.
 
 However, unless you have a pretty large data set, sqlite is probably overkill 
 and it'd be easier to use a plist. I would start with an NSArray of 
 NSDictionaries, and then if it makes the code cleaner replace the 
 NSDictionaries with custom objects containing the fields you're interested in 
 and whatever other methods logically belong there.
 
 NSArrayController can do sorting and filtering of these objects for you for 
 presentation in the table view; if NSArrayController doesn't do what you need 
 then it's easy enough to sort and filter them yourself and then implement the 
 NSTableView data source methods. Take a look at the NSArrayController and 
 bindings API documentation--- if bindings do what you need, they're really 
 quick and convenient.
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/batholdy%40googlemail.com
 
 This email sent to batho...@googlemail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: easy way to store table-like data

2011-03-07 Thread Dave DeLong
If you have an array of dictionaries, you can use -filteredArrayUsingPredicate, 
and pass in the NSPredicate with the format string of @type = 'website'.  
You'll get back all the dictionaries where [[dictionary objectForKey:@type] 
isEqual:@website];

But if you're using these dictionaries for anything more than just transient 
referencing (ie, they're quickly create and destroyed), then I would probably 
recommend making a class to hold the relevant information instead of using a 
dictionary.

Dave

On Mar 7, 2011, at 12:26 PM, Martin Batholdy wrote:

 Hi,
 
 thanks for the reply.
 
 Is it also possible to filter the entries of an NSDictionary like in SQL?
 
 for example I have a key type and different entries.
 
 Is it possible to get an Array of all elements where type is equal to 
 website (or something like that)?
 
 
 
 On 07.03.2011, at 21:05, Wim Lewis wrote:
 
 Well, sqlite3 is available on the system (and is used by a lot of Apple 
 code, so hopefully it won't be removed in the near future); you could simply 
 use that, if that API is what you're most familiar with.
 
 However, unless you have a pretty large data set, sqlite is probably 
 overkill and it'd be easier to use a plist. I would start with an NSArray of 
 NSDictionaries, and then if it makes the code cleaner replace the 
 NSDictionaries with custom objects containing the fields you're interested 
 in and whatever other methods logically belong there.
 
 NSArrayController can do sorting and filtering of these objects for you for 
 presentation in the table view; if NSArrayController doesn't do what you 
 need then it's easy enough to sort and filter them yourself and then 
 implement the NSTableView data source methods. Take a look at the 
 NSArrayController and bindings API documentation--- if bindings do what you 
 need, they're really quick and convenient.
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/batholdy%40googlemail.com
 
 This email sent to batho...@googlemail.com
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/davedelong%40me.com
 
 This email sent to davedel...@me.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSMapTable options

2011-03-07 Thread Ken Thomases
On Mar 7, 2011, at 2:15 PM, Quincey Morris wrote:

 Could someone confirm for me that if I want a NSMapTable object with weak 
 pointers to both keys and values, and that doesn't copy keys or values, the 
 appropriate options are:
 
   [NSMapTable mapTableWithKeyOptions: (NSMapTableZeroingWeakMemory | 
 NSMapTableObjectPointerPersonality) options 
   valueOptions: (NSMapTableZeroingWeakMemory | 
 NSMapTableObjectPointerPersonality)]
 
 Or is [NSMapTable mapTableWithWeakToWeakObjects] sufficient? The 
 documentation doesn't say whether this is modeled after a dictionary (copies 
 keys) or not.

Well, I'm not deeply familiar with this stuff, but I can't see what it would 
mean to have weak references to keys while also copying the keys.

Cheers,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSMapTable options

2011-03-07 Thread Quincey Morris
On Mar 7, 2011, at 12:39, Ken Thomases wrote:

 Well, I'm not deeply familiar with this stuff, but I can't see what it would 
 mean to have weak references to keys while also copying the keys.

OK, I admit I did sit for 5 minutes after reading this trying to think of a use 
for weak references to copies. (You'd have to get 'allKeys' or enumerate the 
keys before the collector had a chance to make off with them.) Another 5 
minutes I'll never get back.

Out of academic interest, then, I wonder what the answer is for strong key 
references.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Validating NSXMLDocument with xml:space attributes

2011-03-07 Thread Heath Borders
I have the following document:

root xmlns=http://example.com/root;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xsi:schemaLocation=http://example.com/root root.xsdfoo
xml:space=preserve there is leading and trailing whitespace here
/foo/root

With the following XSD:

?xml version=1.0 encoding=utf-8?
xs:schema elementFormDefault=qualified
xmlns:xs=http://www.w3.org/2001/XMLSchema;
targetNamespace=http://example.com/root;
xmlns=http://example.com/root;
xs:import namespace=http://www.w3.org/XML/1998/namespace;
schemaLocation=http://www.w3.org/2001/03/xml.xsd; /

!-- Complex types describing all parts of the document --
xs:complexType name=fooType
xs:simpleContent
xs:extension base=xs:string
xs:attribute ref=xml:space fixed=preserve 
/
/xs:extension
/xs:simpleContent
/xs:complexType

!-- The actual schema itself --
xs:element name=root
xs:complexType
xs:sequence
xs:element name=foo type=fooType
minOccurs=0 maxOccurs=unbounded /
/xs:sequence
/xs:complexType
/xs:element
/xs:schema


When I try to validate by reading in my document and then calling:

NSXMLDocument *document = ...
NSError *error = nil;
[document validateAndReturnError:error];

I always get the following errors:

Element '{http://example.com}foo', attribute 'space': The attribute
'space' is not allowed.
Element '{http://example.com}foo', attribute 'space': The attribute
'space' is not allowed.
Element '{http://example.com}foo', attribute 'space': The attribute
'space' is not allowed.


-Heath Borders
heath.bord...@gmail.com
Twitter: heathborders
http://heath-tech.blogspot.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: easy way to store table-like data

2011-03-07 Thread Wim Lewis

On 7 Mar 2011, at 12:26 PM, Martin Batholdy wrote:
 Is it also possible to filter the entries of an NSDictionary like in SQL?

Yes (as Dave DeLong describes). If you just need to filter it for display and 
are using NSArrayController you can also use -setFilterPredicate:. It's 
presumably doing the same thing under the hood.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Setting a delegate on a UITextField

2011-03-07 Thread Jon Sigman
Matt, you are quite correct. It helps to simplify the case, and then build on 
that foundation. I had too many things going on and couldn't see the forest for 
the trees.
Thanks!




From: Matt Neuburg m...@tidbits.com
To: Jon Sigman rf_...@yahoo.com
Cc: cocoa-dev@lists.apple.com
Sent: Mon, March 7, 2011 11:04:25 AM
Subject: Re: Setting a delegate on a UITextField


On Mar 7, 2011, at 9:54 AM, Jon Sigman wrote:

 On Mon, March 7, 2011 9:30:05 AM Matt Neuburg wrote:
 
   The Return key invokes textFieldShouldReturn: and does *not* 
  automatically 
resign first responder ...
 
 Ah! That is the part I had been overlooking. textFieldShouldReturn is the 
perfect place to validate the input.
 
 However, now that I've implemented it, textFieldShouldReturn gets called 
 twice 
immediately when the Return key gets pressed on the keypad, not sure why...
 Thanks!
 

Once again I repeat my advice - start with a totally clean project with nothing 
but a text field and its delegate and watch the delegate messages. Keep it 
*simple* when exploring the framework. You will see that what you're saying is 
false. The sequence will be:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(@%@, NSStringFromSelector(_cmd));
[textField resignFirstResponder];
return YES;
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
NSLog(@%@, NSStringFromSelector(_cmd));
return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
NSLog(@%@, NSStringFromSelector(_cmd));
}

2011-03-07 11:02:00.934 Crud[7945:207] textFieldShouldReturn:
2011-03-07 11:02:00.936 Crud[7945:207] textFieldShouldEndEditing:
2011-03-07 11:02:00.938 Crud[7945:207] textFieldDidEndEditing:

Now add your validation.

I really can't advise using textFieldShouldReturn: for validation, because 
there 
are many *other* ways in which a text field might resign first responder, and 
then you'd miss out on your validation test. It is best to adopt habits that 
work in general, with the intent of the framework, rather than just going with 
something that happens to seem to work okay in one limited case. m.

--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
Programming iOS 4! http://www.apeth.net/matt/default.html#iosbook
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com


  
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


kvo

2011-03-07 Thread Ariel Feinerman
Hi,

I wish to use kvo to get data from NSOperation and observe isFinished but on
witch thread is - observeValueForKeyPath:ofObject:change:context: executed?

-- 
best regards
Ariel
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: kvo

2011-03-07 Thread Kyle Sluder
On Mon, Mar 7, 2011 at 3:23 PM, Ariel Feinerman arielfap...@gmail.com wrote:
 Hi,

 I wish to use kvo to get data from NSOperation and observe isFinished but on
 witch thread is - observeValueForKeyPath:ofObject:change:context: executed?

From the NSOperation documentation:

Although you can attach observers to these properties, you should not
use Cocoa bindings to bind them to elements of your application’s user
interface. Code associated with your user interface typically must
execute only in your application’s main thread. Because an operation
may execute in any thread, KVO notifications associated with that
operation may similarly occur in any thread.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Proper way to construct an Attribute NSXMLNode so that its prefix is included in its XMLString

2011-03-07 Thread Matt Neuburg

Thus, I do the following:

NSXMLElement rootXmlElement = ...
NSXMLNode *schemaLocationAttributeXmlNode =
  [NSXMLNode attributeWithName:@schemaLocation URI:@xsi
stringValue:@http://example.com/document document.xsd];

So, now, I tried specifying the prefix in the attribute name when
creating the attribute:

NSXMLElement rootXmlElement = ...
NSXMLNode *schemaLocationAttributeXmlNode =
  [NSXMLNode attributeWithName:@xsi:schemaLocation
URI:@http://www.w3.org/2001/XMLSchema-instance;
stringValue:@http://example.com/document document.xsd];
   
[rootXmlElement addAttribute:schemaLocationAttributeXmlNode];

Success!

This doesn't seem consistent with the documentation.

They haven't made it terribly clear, have they? I would have done it like this:

NSXMLElement* e = [[NSXMLElement alloc] initWithName: @document];
NSXMLNode* def = [NSXMLNode namespaceWithName:@ 
  
stringValue:@http://example.com/document;];
[e addNamespace:def];
NSXMLNode* xsi = [NSXMLNode predefinedNamespaceForPrefix:@xsi];
[e addNamespace:xsi];
NSXMLNode* loc = [NSXMLNode attributeWithName:@xsi:schemaLocation 
  stringValue:@http://example.com/document 
document.xsd];
[e addAttribute: loc];

But that does leave one wondering what the URI param is for...

m.


--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Event Tap(CFMachPortRef) problem for Hot Key- callback is not invoked

2011-03-07 Thread Deepa
Hi,

I am developing a desktop application that supports one of the feature through 
Hot Key. I am using Event Tap for this to work. 

But, sometimes (randomly) the callback is not invoked; Hot Key does not work 
and hence the feature seems to be not working. 

Could someone help me out in identifying the problem here.

Following is the code snippet:

   -( void )startEventTapinThread //Called in a separate thread.
   {
NSAutoreleasePool *pool =[ [ NSAutoreleasePool alloc] init];

CFRunLoopRef runloop =(CFRunLoopRef)CFRunLoopGetCurrent();
CGEventMask interestedEvents = 
CGEventMaskBit(kCGEventFlagsChanged)|CGEventMaskBit(kCGEventKeyDown);
CFMachPortRef eventTap = CGEventTapCreate(kCGSessionEventTap, 
kCGHeadInsertEventTap, 0, interestedEvents, myCGEventCallback, self); 
//self is the object pointer our method
CFRunLoopSourceRef source = 
CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
CFRunLoopAddSource((CFRunLoopRef)runloop , source, 
kCFRunLoopCommonModes);
CFRunLoopRun();
[ pool release];
   }

   CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, 
CGEventRef event, void *refcon)
   {
CGEventType eventType = CGEventGetType(event);
//execute the code related to feature
   }

Thanks and Regards,
Deepa---
Robosoft Technologies - Come home to Technology

Disclaimer: This email may contain confidential material. If you were not an 
intended recipient, please notify the sender and delete all copies. Emails to 
and from our network may be logged and monitored. This email and its 
attachments are scanned for virus by our scanners and are believed to be safe. 
However, no warranty is given that this email is free of malicious content or 
virus.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSThread

2011-03-07 Thread Bruno Causse
hi all,

how many NSThread i can create?

what happens when the limit is exceeded?

seems [[NSThread alloc] initWithTarget] never returns nil :(

thx a lot
--
Bruno Causse

BEGIN:VCARD
VERSION:3.0
N:Causse;Bruno;;;
FN:Bruno Causse
EMAIL;type=INTERNET;type=HOME;type=pref:bruno.cau...@free.fr
TEL;type=HOME;type=pref:0148997352
item1.ADR;type=HOME;type=pref:;;33\, quai de halage;Créteil;;94000;France
item1.X-ABADR:fr
X-ABUID:B525FD38-719B-4EC3-88E5-B7DEE9A5F246\:ABPerson
END:VCARD


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Crash with extra [CFString release] after changing a bound value in NSTextField

2011-03-07 Thread John Link
My app has a window with many text fields and a button. The value in each text 
field is bound to Shared Defaults. Clicking the button reads from the defaults 
and generates text which is written to a text field in a second window.

The app launches with the previously used values in the text fields (as 
desired). Immediately clicking the button works fine--text is generated as 
expected. But if I change the value in a text field before clicking the button, 
the app crashes. (This happens whether or not I first tab out of the field to 
commit the edit before clicking the button.) The error is:

-[CFString release]: message sent to deallocated instance 0x164d7fd0

That leads to:

Call [2] [arg=32]: thread_a0871720 |start | main | NSApplicationMain | 
-[NSApplication run] | -[NSApplication sendEvent:] | -[NSWindow sendEvent:] | 
-[NSTextView keyDown:] | -[NSView interpretKeyEvents:] | -[NSTSMInputContext 
interpretKeyEvents:] | -[NSKeyBindingManager(NSKeyBindingManager_MultiClients) 
interpretEventAsCommand:forClient:] | -[NSTextView doCommandBySelector:] | 
-[NSResponder doCommandBySelector:] | -[NSTextView(NSKeyBindingCommands) 
insertTab:] | -[NSTextView(NSPrivate) _giveUpFirstResponder:] | -[NSWindow 
makeFirstResponder:] | -[NSTextView(NSSharing) resignFirstResponder] | 
-[NSTextField textShouldEndEditing:] | -[_NSBindingAdaptor 
validateAndCommitValueInEditor:editingIsEnding:errorUserInterfaceHandled:] | 
-[_NSBindingAdaptor 
_validateAndCommitValueInEditor:editingIsEnding:errorUserInterfaceHandled:bindingAdaptor:]
 | -[NSValueBinder 
validateAndCommitValueInEditor:editingIsEnding:errorUserInterfaceHandled:] | 
-[NSValueBinder 
_applyDisplayedValueIfHasUncommittedChangesWithHandleErrors:typeOfAlert:discardEditingCallback:otherCallback:callbackContextInfo:didRunAlert:]
 | -[NSValueBinder 
applyDisplayedValueHandleErrors:typeOfAlert:canRecoverFromErrors:discardEditingCallback:otherCallback:callbackContextInfo:didRunAlert:]
 | -[NSActionCell objectValue] | -[NSControl validateEditing] | -[NSCell 
setStringValue:] | -[NSCell _objectValue:forString:] | -[NSCell 
_objectValue:forString:errorDescription:] | -[NSPlaceholderString 
initWithString:] | CFStringCreateWithCharactersNoCopy | 
__CFStringCreateImmutableFunnel3 | _CFRuntimeCreateInstance | malloc_zone_malloc

I tried adding [myWindow makeFirstResponder:nil] at the beginning of the 
button's action but that didn't work. The odd thing is that the crash only 
affects certain text fields and not others. (All are identical except for their 
Model Key Paths.) I'm a bit of an amateur and any help would be most 
appreciated. 
Thanks,
John


  
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSXMLParserDelegateAbortedParseError

2011-03-07 Thread Josh Caswell
This is a copy-paste of a question I asked on StackOverflow 
http://stackoverflow.com/questions/5132266/nsxmlparser-error-code-changes-after-abort,
which hasn't gotten any answers. I'm still curious about it and hoped I
might get a response on this list; apologies to anyone who is reading it
twice now.

I'm using an NSXMLParser on some data that I request from a server on the
net. It's possible that one of the arguments to the request is not to the
server's liking, and it will return some XML with an Error element. In that
case, I present the server's error text in an alert sheet, so the user has
some idea what may have gone wrong. My parser delegate facilitates this by
saving the contents of the ErrorMessage element that the parser finds, and
then calling [parser abortParsing]

The error code that results from this is supposed to be code 512,
NSXMLParserDelegateAbortedParseError, and, indeed, when my delegate
implements:

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError
*)parseError {
NSLog(@Parse Error Code: %d, [parseError code]);
}
I see 512 in the log. So far, so good.

Now, my parser delegate returns the result of [parser parse] to my
controller. The controller checks that result, and if it's NO, it checks the
code in the error pointer that it passed, to see if failure was due to the
delegate aborting:

// In MyParserDelegate.m
- (BOOL)parseData:(NSData *)data
 intoDict:(NSMutableDictionary *)dict
   errPtr:(NSError **)errPtr {
// ...
BOOL successful = [xmlParser parse];
if( !successful  (errPtr != NULL) ){
*errPtr = [parser parserError];
NSLog(@Delegate: Parser Error Code: %d, [*errPtr code]);
// Should be 512 after abort? Is actually 1...
}

return successful;
}

// In MyController.m
BOOL successful = [parserDelegate parseData:data
   intoDict:dict
 errPtr:error];
if( !successful ){
NSLog(@Controller: Parse Error Code: %d, [error code]);
// Should be 512 after abort? Is actually 1...
}
I expect this to be the same code 512, but it turns out that it is code 1,
NSXMLParserInternalError! I'd like to figure out what's going on here so I
don't end up trying to present an error in the wrong circumstances.

The obvious ways around this are to either post a notification or implement
a flag (which I did) in the delegate so it knows when it aborted, and can
construct its own NSError to return in place of the actual parserError.

I'm just trying to understand why the error code changes like this. Is the
delegate supposed to do something in parseErrorOccurred: to tell the parser
that it should hold onto the AbortedParseError? (The only Sample Code that
checks for that error also ignores it.) Also, not knowing the circumstances
that would otherwise cause an NSXMLParserInternalError (Apple's description
of it is so wonderfully eloquent), I would like to avoid catching it when I
didn't mean to. Can anyone enlighten me, particularly on the question of the
code change?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


How to wait for methods with result/completion blocks to finish?

2011-03-07 Thread Chris Markle
This is on iOS... Say I have use a method that has some kind of
result/completion block like ALAssetsLibrary assetForURL In the
example below, in the assetForURL result block, the JPEG
representation of the asset is read into a buffer and the NSData form
of that buffer is assigned to a property. I need the property to be
set before my code continues past his point. How do I go about
accomplishing that? Am I forced to show a waiting for xxx view until
this finishes?

I tried surrounding the assetForURL call with a semaphore but this
does not work on the main app thread (the dispatch_semaphore_wait()
blocks the main thread and thus the dispatch_semaphore_signal() in the
resultBlock never gets to run to signal that the block is done).

I guess in general I an wondering how I correctly wait for things to
happen that I absolutely positively need to be done before I
continue...

Thanks in advance...

Chris

* * *

-(void)getJPEGFromAssetForURL:(NSURL *)url {
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:url
resultBlock: ^(ALAsset *myasset) {
ALAssetRepresentation *rep = [myasset defaultRepresentation];
Byte *buf = malloc([rep size]);
NSError *err = nil;
NSUInteger bytes = [rep getBytes:buf fromOffset:0LL
length:[rep size] error:err];
if (err || bytes == 0) {
[...]
}
self.imageJPEG = [NSData dataWithBytesNoCopy:buf
length:[rep size] freeWhenDone:YES];
}
failureBlock: ^(NSError *err) {
NSLog(@can't get asset %@: %@, url, err);
}];
[assetslibrary release];
}
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Crash with extra [CFString release] after changing a bound value in NSTextField

2011-03-07 Thread Quincey Morris
On Mar 7, 2011, at 14:01, John Link wrote:

 The app launches with the previously used values in the text fields (as 
 desired). Immediately clicking the button works fine--text is generated as 
 expected. But if I change the value in a text field before clicking the 
 button, 
 the app crashes. (This happens whether or not I first tab out of the field to 
 commit the edit before clicking the button.) The error is:
 
 -[CFString release]: message sent to deallocated instance 0x164d7fd0

So you know this is a memory management error -- a string has been 
overreleased. What's your code to change the value in a text field?


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Length of NSWindow's stringWithSavedFrame result?

2011-03-07 Thread John Bartleson
In my NSDocument-based app I'm saving and restoring the window frame  
to/from an xattribute using

NSWindow's stringWithSavedFrame and setFrameFromString: methods.

During doc save in MyDocument.m I save the frame in an override of  
setFileURL:

- (void)setFileURL:(NSURL *)absoluteURL
{
[super setFileURL:absoluteURL];
// Save the window frame to the file's extended attributes
NSString *frameNSString = [[tableView window]  
stringWithSavedFrame];

// Only do the save if window frame exists.
// i.e., if we're called during document save, not during  
document init

if ( [frameNSString length] ) {
const char *frameCString = [frameNSString UTF8String];
int result = setxattr( [[absoluteURL path]  
fileSystemRepresentation],
[JBMainWindowXattrName  
UTF8String],
frameCString,  
strlen(frameCString) + 1,

0, 0 );
}
}

Upon doc load I restore the frame in an override of  
windowControllerDidLoadNib:

- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
// For existing files, get the window frame from the file's  
extended attributes.

NSURL * theURL = [self fileURL];
if ( theURL ) {	// If we're loading an existing file, rather than  
a new one

char frameCString [50];
ssize_t bytesRetrieved = getxattr( [[theURL path]  
fileSystemRepresentation],
 
[JBMainWindowXattrName UTF8String],
 
frameCString, 50,
 
0, 0 );

if ( bytesRetrieved  0 ) {
[[tableView window] setFrameFromString:[NSString  
stringWithUTF8String:frameCString]];

}
}
}

This all works great. There's only one problem: the size of the string  
returned by stringWithSavedFrame.


On my single-monitor system, the returned string looks like this:
552 789 1312 260 0 0 1920 1178
i.e. eight integers, four representing the window frame and four  
representing the screen frame.
This takes about 30 bytes. I'm suspicious, though, that the 50 bytes  
I've allowed for the
string returned by getxattr in the second method above might not be  
enough on a multi-monitor
system. Can anyone tell us what the string returned by  
stringWithSavedFrame looks like on a

multi-monitor system?


--
Vielen Dank to Uli Kusterer for the idea to use an xattribute for  
this, and for publishing his

UKXATTRMETADATASTORE wrapper class.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSThread

2011-03-07 Thread Bill Bumgarner

On Mar 7, 2011, at 12:27 PM, Bruno Causse wrote:

 hi all,
 
 how many NSThread i can create?

Quite a few more than are useful, performant, or optimal...

b.bum

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


About notification NSWindowDidMiniaturizeNotification

2011-03-07 Thread Ivan Chen
Hi,
Guys

I write the following code and try to observe the window miniaturized 
notification, it doesn't work, can anyone tell me why?


- (void)windowMiniaturized:(NSNotification*)notification
{
NSLog(@%@, notification);
}

- (void)registerDefaultNotification:(NSString*)notification 
withSelector:(SEL)selector onObject:(id)object
{
[[NSNotificationCenter defaultCenter] addObserver:self   
 selector:selector   
 name:notification   
   object:object];


}

// Observing window status
[self registerDefaultNotification:NSWindowDidMiniaturizeNotification 
withSelector:@selector(windowMiniaturized:) onObject:nil];







Thanks
Ivan Chen___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


how to start rainbow cursor

2011-03-07 Thread Yu, Min
Hi list

how to start rainbow cursor?


Do you have any hint?
Thanks you in advance.

Yu Min
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com