Category 'D'


iPhone: the most useful tag property

All objects that derive from <a target="_blank" href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/cl/UIView">UIView</a> inherit the useful properties <a target="_blank" href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW25">tag</a> This property is a real user-data (a "place" that the developer used for general purposes) of type <a target="_blank" href="http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/NSInteger">NSInteger</a> so where we can store only numbers.

The uses to which they can obviously depends on the circumstances however, it is useful to identify a particular object to taking a common occurrence. For example, imagine you have two <a target="_blank" href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIAlertView_Class/UIAlertView/UIAlertView.html">UIAlertView</a> respond to the same event:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/ / First alert
[ [ UIAlertView alloc ] initWithTitle : @ "Primo" message : @ "Primo Alert" delegate : self cancelButtonTitle : @ "OK" otherButtonTitles : nil , nil ] ; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "First" message: @ "First Alert" delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil, nil];
; [Alert show];
; [Alert release];

/ / ...

/ / Second alert
[ [ UIAlertView alloc ] initWithTitle : @ "Secondo" message : @ "Secondo Alert" delegate : self cancelButtonTitle : @ "OK" otherButtonTitles : nil , nil ] ; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Second" message: @ "Second Alert" delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil, nil];
; [Alert show];
; [Alert release];

/ / Event
/ / OK button Cliccandi of this function will be called Alter
void ) alertView : ( UIAlertView * ) alertView clickedButtonAtIndex : ( NSInteger ) buttonIndex { - (Void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) {buttonIndex
/ / Todo
}

Note: code examples in C + + you will find directions. This is not entirely correct because, as you know, the language is Objective-C. This is due to the fact that the plugins I use to view the source code does not support Objective-C and C + + is the one that best approaches him.

How to differentiate between the two alert? Precisely using the property tag. After creating the alert just enter:

1
2
3
4
5
6
7
8
9
10
11
12
13
/ / First alert
[ [ UIAlertView alloc ] initWithTitle : @ "Primo" message : @ "Primo Alert" delegate : self cancelButtonTitle : @ "OK" otherButtonTitles : nil , nil ] ; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "First" message: @ "First Alert" delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil, nil];
1 ] ; // imposto il tag di questo Alert ad 1 [Alert SETTING: 1] / / set the tag of this Alert to 1
; [Alert show];
; [Alert release];

/ / ...

/ / Second alert
[ [ UIAlertView alloc ] initWithTitle : @ "Secondo" message : @ "Secondo Alert" delegate : self cancelButtonTitle : @ "OK" otherButtonTitles : nil , nil ] ; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Second" message: @ "Second Alert" delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil, nil];
2 ] ; // imposto il tag di questo Alert ad 2 [Alert SETTING: 2] / / set the tag of this Alert to 2
; [Alert show];
; [Alert release];

Now modify the event in order to understand which Alert has been closed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/ / Event
/ / OK button Cliccandi of this function will be called Alter
void ) alertView : ( UIAlertView * ) alertView clickedButtonAtIndex : ( NSInteger ) buttonIndex { - (Void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) {buttonIndex
alertView.tag ) { switch (alertView.tag) {
: case 1:
/ / First Alert
break;
: case 2:
/ / According Alert
break;
default:
break;
}
}

Exact same technique can be used if we have a series of <a target="_blank" href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIButton_Class/UIButton/UIButton.html">UIButton</a> run-time. For example:

1
2
3
4
5
6
7
8
9
10
unsigned int i = 0 ; i < 10 ; i ++ ) { for (unsigned int i = 0; i <10; i + +) {
[ [ UIButton buttonWithType : UIButtonTypeCustom ] initWithFrame : CGRectMake ( i * 20 , i * 20 , 20 , 20 ) ] ; UIButton * myButton = [[UIButton buttonWithType: UIButtonTypeCustom] initWithFrame: CGRectMake (i * 20, * 20, 20, 20)];
@ "But" forState : UIControlStateNormal ] ; [MyButton setTitle: @ "But," Forst: UIControlStateNormal];
i ] ; // imposto il tag [MyButton SETTING: i]; / / set the tag

/ / The same event for all
self action : @selector ( onTouchUpInside : ) forControlEvents : UIControlEventTouchUpInside ] ; [MyButton addTarget: self action: @ selector (onTouchUpInside:) forControlEvents: UIControlEventTouchUpInside];

mybutton ] ; [Self.view addSubview: myButton];
}

(dove eseguiamo un casting <a target="_blank" href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/cl/UIView">UIView</a> In the event onTouchUpInside recover from the sender (where we perform a casting <a target="_blank" href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/cl/UIView">UIView</a> the property <a target="_blank" href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW25">tag</a>

1
2
3
4
void ) onTouchUpInside : ( id ) sender { - (Void) onTouchUpInside: (id) sender {
( ( UIView * ) sender ) .tag; button_tag unsigned int = ((UIView *) sender). tags;
/ / Todo
}

Continued ...

Very short snippet: Display a list of posts by category or tags

Two useful features, customizable at will, to be used to show the last n posts of a category or one or more tags. Functions, as you will see, are very similar and are both based on a loop generated by query_post() . The first, show_title_cat() , shows the last post (in this version only the title) of a specific category:

Continued ...

A WordPress theme for all

Under the heading of the blog, on the left, just above the navigation bar, there is a "switch" that allows you to switch to an alternate graphic theme, namely "clear".

The graphic theme of a blog is chosen by the blog owner himself, or if it is created by hand, whether it was downloaded from the network. The end result, however, in addition to "us" owners should be pleased by our visitors who do not always appreciate certain layout choices. For some it will be trivial for other wonderful, for others still terribly annoying! So why not to choose the "visitor" to display the layout with our blog?

Continued ...

Hi Phone

iphone From today inaugurated a new section (category to be corrected) dedicated to developing applications on Apple iPhone! I state now that many of the items that will publish a "cut" in line with the spirit of this blog, that will be mostly for advanced users. However, as I have done for other topics, I'll try to be as clear as possible and, where necessary, to insert some "basic concept" useful to a wider audience.

Continued ...

Very short snippet: PHP slug

Who develops to WordPress definitely knows the word slug , usually used to indicate the text strings that do not contain spaces or other "strange" characters. In practice a friendly URL string, which can be used within a URL.

Continued ...

Very short trick: Conditional CSS and optimization

The use of conditions within the browser is often used to decide which style sheet to load depending on the type of browser. For example we can use this code to load a particular style sheet when the browser is Internet Explorer 6:

Continued ...

On the structure of objects of a Wordpress Plugin

If we rely on the simple example hellodolly.php provided by WordPress , or even the same official documents, never comes to writing a good and efficient plug-in. We want here to analyze a possible structure, then a skeleton that can be used multiple times.

Continued ...

Shadowbox 3.0 beta

It was released right now (thanks to alert the author Michael JI Jackson ) release 3.0 beta Shadowbox.js . In addition to the new site design here is the most important changes prior to this release:

Continued ...

WordPress MU: aggregate individual blogs Tag cloud

It could never happen have to aggregate the individual tag cloud by WordPress MU. In addition, in certain contexts, it may not make sense to show a "cloud" with the tag blog heterogeneous. However, in the unlikely event that someone was for, so here is a simple way to show a tag cloud aggregate.

Continued ...

Very short snippet: Actionscript extend an array by the method shuffle ()

I had already talked about how to implement the method shuffle () in Javascript and Actionscript . I realized, tuttaavia, not pointing out that it is able to extend Actionscript, Javascript in the same way, its object Array :

Continued ...