Jul 18, 2008

(Objective-c) Comment récupérer le chemin d'un fichier dans le projet sous XCode

En Objective-C, nous devons avoir le chemin absolue pour lire unfichier, même ce fichier est dans le meme répertoire des fichiers sources. Mais pour une application mobile, cette manipulation ne marche plus, parce que l'appareil mobile ne possède pas de même structure de fichier par rapport les ordinateur.

Une solution pour résoudre ce problème, mettre ce fichier dans la "Resource" de XCode, n'oublie pas cocher la case de le copier. Pour récupérer le chemin vers ce fichier:

NSString* designFilePath = [[NSBundle mainBundle] pathForResource:@"design" ofType:@"xml"];

Le fichier est "design.xml".

(Objective-c) How to realize multiple inheritance

The Objective-c is single inheritance, but using Protocol allows to implements multiple class's methods, just like Interface in JAVA.

Here is an example :

@protocol MouseListener
-(BOOL) mousePressed;
-(BOOL) mouseClicked;
@end
@protocol KeyboardListener
-(BOOL) keyPressed;
@end
@interface Toto : NSObject
{
...
}
@end

So in the implementation of Toto we could override these listener's methods.

Jul 16, 2008

(IPhone) How to catch a button's click event

Here is an example:

//ViewBasedAppDelegate.h
#import

@class ViewBasedViewController;

@interface ViewBasedAppDelegate : NSObject {
UIWindow *window;

}

@property (nonatomic, retain) UIWindow *window;
-(void) catchButton;

@end

//ViewBasedAppDelegate.m
#import "ViewBasedAppDelegate.h"

@implementation ViewBasedAppDelegate
@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(10.0, 90.0, 160.0, 40.0);
[button setTitle:@"Button" forState:UIControlStateNormal];
[button addTarget:(id)self action:@selector(catchButton)
forControlEvents:UIControlEventTouchUpInside];
[window addSubview:button];
[window makeKeyAndVisible];

}

- (void)catchButton{
NSLog(@"button pressed");

}

- (void)dealloc {
[window release];
[super dealloc];
}

@end

Jul 15, 2008

(IPhone) How to use NSXmlDocument in the IPhone's application

The sdk final didn't included NSXmlDocument, there is only NSXmlParser, the reason is the weight problem, NSXmlParser is lignter.

But in some cases, the Dom is more userful than SAX, with some google research, i found the API of TouchXml, http://code.google.com/p/touchcode/.

It solved the problem to use NSXmlDocument in the applicatons. Don't forget to check out all source files and add 2 parameters in project.

OTHER LINKER FLAGS = -lxml2
HEADER SEARCH PATHS = /usr/include/libxml2

Jul 7, 2008

(IPhone) Dev on IPhone started

Today i put my feet on the IPhone world, i'm so exciting. So the dev started with reading docs and sample codes.

Jun 23, 2008

(SQLite) Good Add-ons of SQLite for Firefox

There is a good tool of SQLite which is an Add-ons of Firefox, it allows to consult database's informations.

Here is the link : https://addons.mozilla.org/en-US/firefox/addon/5817

Jun 10, 2008

(Android) Is this a problem of BaseAdapter?

I created a object of ListView and my own LinearLayout for each row. The first row contains each column's name, so when i refresh this ListView, the first row don't change, so i pass the first row's value to a variable, and use clear() to remove all my ListView's element, and then add the variable in the ListView. I thought what i should do is create new LinearLayout and add them in ListView, with notifyDataSetChanged() method the ListView should be refreshed.

A problem comes, in the "refreshed" ListView there isn't new values, the values displayed are the first row which contains all column's name and the first row of value which should be deleted by the below clear().

I checked the list in the adapter of ListView, all the new values didn't added in the adapter's list. I can't figure out what is going on here.

The solution i found right now is after clear all the items, create a new adapter like adapter = new MyAdapter(this), and don't forget reset this adapter in the ListView.