miércoles 3 de junio de 2009

Scalling UIView and all its content

I have been looking for several days to find a way to scale an UIView and all its content, at the end the solution is simple:

self.transform = CGAffineTransformMakeScale(1.1, 1.1);
(been self the UIView)

it is so simple that is embarrassing :), a code snip of my example, when you push the view it gets bigger 10%:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
self.transform = CGAffineTransformMakeScale(1.1, 1.1);
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
self.transform = CGAffineTransformMakeScale(1, 1);
}

domingo 12 de abril de 2009

Understanding a bit better Interface Builder

If you have been playing with Interface Builder for the iPhone development and you have found it a bit difficult to understand, here is a post with some basic ideas to help you to understand how it works and interact with your code.

As a newbie on the iPhone, but more on Mac development, this tool is a bit weird and difficult to understand from the beginning.
The basic difference is that when you load Xib files you create instances of the objects defined inside, in opposition to other tools, like let’s say Visual Basic, which generates code. Interface Builder also creates the links among the components and actions defined in the Xib file and your code when it is loaded.

The first point is the three objects that appears the first time you open a Xib file:
File’s Owner, First Responder and the Application delegate.
Not all classes included in the Xib file are instantiated, there are also Proxy Objects, these proxy objects are in fact references to instances in your code, these are the links between your code and the objects created out of the Xib file, when the file is loaded.

To understand what is the File’s owner you need to see the code uses to load the Xib file:
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@”CustomCell” owner:self options:nil];

In this line, self is the File’s owner. In the process of loading the file and creating the instances of the objects defined inside, this process also links the IBOutlets defined in the File’s Owner with the instances.
If you select File’s Owner and open the Connections Inspector (Tools->Connections Inspector (⌘ 2)) you will see the object names linked with the outlets of the selected object.

First Responder is also a proxy object, it points to the first responder in the responder chain. This allows you to send messages to the responder chain throw this element. With the Identity Inspector (Tools -> Identity Inspector (⌘ 4)) you can see and add new Actions to the First Responder. You can then link, for instance, the push of a button to these actions.

It is more frequent to send actions to functions in objects using the IBAction keywork, so the fact is that usually you don’t send messages to the First Responder but you link actions in buttons to specific functions in classes, defined this way:
- (IBAction)touchGo:(id)sender;

The Application delegate is another proxy object that only appears in the “MainWindow.xib” when an application is created by XCode, there is a link automatically created among the File’s owner delegate Outlet and this Application delegate (to see this select the File’s owner and push ⌘ 2).

You can also see (selecting the Connections of the application delegate) how the outlets defined in AppDelegate.h are linked with the window and the UINavigationController (in case of an application of this kind) with those elements in the MainWindow.xib

@interface CustomTable1AppDelegate : NSObject {

IBOutlet UIWindow *window;
IBOutlet UINavigationController *navigationController;
}




The main idea, again, is that the objects that you create on the Xib file are in fact instances, created when the Xib file is loaded. And to have access to those objects you have to create Outlet to link you code with those instances, or if you load directly a Xib file calling loadNibNamed:owner:options: you can go through the array returned to access directly the objects instanciated.

It is quite frequent to have custom UITableViewCell in a Xib file and load it programmatically and access the cell with this code:
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:XibName owner:self options:nil];
cell = [nib objectAtIndex:1];


Hopefully this has help you to understand how IB works.

sábado 7 de febrero de 2009

Navigation Controller with Toolbar

I was trying to do this, add a UIToolbar to a Navigation Controller (UINavigationController),

I found this example Navigation Controller + UIToolbar but it inserts the toolbar programmatically.

I have been playing with the Interface Builder until I have managed to include the toolbar with minimal code, this way...

First, you have to create a new Navigation-Based Application. Then you open MainWindow.xib with the Interface Builder and include a Toolbar bellow the Window.


You must drag the Toolbar from the Library to the Nib document window, bellow the Window object to look this way (selecting this list View Mode):


and then set the position of the toolbar inside the window at the bottom (you can hit twice on Toolbar or Window to make this window appears):


You need to do some coding to make the toolbar appears in the right position:
Inside the application delegate class you need to include an outlet as reference to the Toolbar, in <Applicaton>AppDelegate.h:

@interface Windows2AppDelegate : NSObject {

IBOutlet UIWindow *window;
IBOutlet UINavigationController *navigationController;
IBOutlet UIToolbar *toolbar;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UINavigationController *navigationController;
@property (nonatomic, retain) UIToolbar *toolbar;

@end


and in your <Application>AppDelegate.m:

@implementation Windows2AppDelegate

@synthesize toolbar;

[...]
- (void)applicationDidFinishLaunching:(UIApplication *)application {

// Configure and show the window
[window addSubview:[navigationController view]];
[window addSubview:toolbar];
[window makeKeyAndVisible];


(and the release if you like in the dealloc method).

In the code above the toolbar should be added to the window (addSubview:) after the navigationController, this way the toolbar is visible.

And finally link the Toolbar in the Interface Builder with toolbar outlet in our code.



and that’s it.
If you are interested, The original article provides additional source code about how to move among views.

martes 27 de enero de 2009

iPhone/Objective-C development resources

After some months developing for the iPhone I have found useful code, libraries, resources that could be useful to other developers and save time (a note, I have used only some of them):

SQLite ORMs
Persistent Objects, it allows to save and load a complex data structure in SQLite in a complete transparent way (you don't have to define even the database file name), I love it. This has a cost, the database structure is not the optimal.
ActiveRecord, I found this one complex to install for iPhone development. The approach is different, this one creates the classes that map the database, PersistentObjects creates the database that maps the objects.

HTTP Request (for RESTful APIs, POST/GET and more)
Objective-C REST Client, short library, easy to adapt to your own requirements.

JSON
JSON Framework, I used this one...
TouchJSON, ... but people seems to like more this one (I haven't try)

Inter-threading communication
ActorKit

Books
The iPhone Developer's Cookbook: Building Applications with the iPhone SDK by Erica Sadun, I think this one was the first one and, in any case, is the one I have. For me a good book and the source code is available here, besides that she has set up a google group iPhoneSDK with lot of activity.

Other books are appearing, for instance, this one for beginners Beginning iPhone Development: Exploring the iPhone SDK , in iPhone development, not in Objective-C (it has a lot of success, I can’t talk about the quality I don’t know).

Google Groups
I have found two groups with significant activity:
iPhoneSDK , mentioned previously, and
iPhone SDK Development

Curiosities
Today I have found this Google docs spreadsheet with twitter URLs of iPhone developers. (mine for SmartTime is included ;) )
You can include new ones in this form.

That’s all.
Comments? Something missed?

--edu

sábado 3 de enero de 2009

Nozbe2SmartTime iPhone application


I have started a project, an application for the iPhone: Nozbe2SmartTime, that allows to see in the iPhone the tasks stored in Nozbe.com and copy them into the SmartTime application.

I'm using Nozbe for some months now and I found it very useful for tracking all my TODOs. I started to use also SmartTime, which is more focused on organizing the day by day tasks so they complement each other very well, and they fix very well in my way of doing things.

But I found myself in the tedious task of reviewing the Nozbe page and copy the text into the SmartTime application frequently so I started this project to make all this process smoother.

I'm doing this on my spare time so to motivate myself you can follow my work here:
* The website of the project.
* Nozbe2SmartTime Twitter with the day by day progress.

Even if you don't have SmartTime I plan to add some functionality to control de Tasks in Nozbe from the same application (although Nozbe is planning to release an iPhone appication and also although the public API has "some" limitations), this application allows to see all your tasks and projects in one view (which is one of the shortcomings of Nozbe).

For those who have the jailbraked iPhone you can find the last IPA file in the download area, or also download the source code with Subversion. The license of the code is GPLv3 (sincerely, mainly because the people of leftcoastlogic.com didn't provide the minimal help with the URL they use to make backup of the tasks, which btw is the method I use for the integration).

If you use this application, please let me know.

Update: some pictures of the application: http://twitpic.com/photos/Nozbe2SmartTime

--Edu

domingo 14 de diciembre de 2008

Business based on iPhone applications

I have just read this blog entry "Financial Realities of the App Store" with economic details of a startup trying to survive to how iPhone applications are structured and distributed inside App Store.
What is extremely interesting of this entry is that it provides lot of details about how the business is running and their efforts to promote the applications on AdMon and AdWords, what seems very expensive and of low efficiency (one comment that stuck in my mind is the price of $0.37/click in AdWords).

So I'm going to list the things that in my opinion are horrible in AppStore:

- The way applications are structured in iTunes, and how to surf over all them (10,000) trying to find something valuable for you. Clearly the model followed to sell music is not applicable to applications and they have to improve the searching and the accessibility to the details and comments of the applications. The reality is that unless you are looking for something concrete that you have read on the press or in blogs, it is impossible to find any application among thousand existing in the app store.

- iTunes being the only way to sell or distribute applications. This is completely unusual and it's based on the strong position of Apple right now (imagine all Mac applications sold only by Apple). They are making a lot of money just with the distribution of applications charging developers with 99$ per year just to be able to test the application on a physical device and distribute it in the app store... (plus 30% of all the sales). So if you plan to make a small application perhaps useful to a little group of people and your idea is to distribute it for free you have to pay 99$ per year any way... not to mention the amount of crap you can find in the app store.

- The lack of a shareware or the ability to temporally test an application and buy it if you find it useful. Now you have like a number of promotional codes, which is useful to distribute the application to journalists or a limited set of users but not as a general promotional strategy.

- Apple evaluates all the applications to test first that the application doesn't break the phone (which seems ok) and second that the functionality provided is not the same already provided by the iPhone...hmm!, I only see a vast number of really bad, stupid, useless applications repeated until the infinitive but you know Opera web browser for the iPhone was blocked because it doesn't provide additional functionality to Safari... did you notice the mafia behaviour here?.

- And finally, I have seen in posts in Apple's Forum people complaining about the way Apple distribute the profit. Apple only distribute the money when you reach 250$ but in one country (or zone)... meanwhile Apple retains the money for you. I don't know the details of this, I hope that even when you are bellow the 250$ threshold you get the money some moment in time but I can ensure you that they take my money intermediately when I buy something and don't wait I spend more that 250$ to get my money :)

I really don't understand how people is able to distribute applications for free in iTunes without any collateral benefit (RTM for instance, is an impressive application but force people to go to a Pro account in their web application, so there is a business model behind... but others like Darts, a quite cool game is free and quite funny to me, as far as I know they are only spending money for the fun of others, they have win the heaven but have ruined their company :), actually is Brian Hammond ).

domingo 26 de octubre de 2008

Windows Vista SP1 without connection to Internet Solved

Today I have had an important problem with my Windows Vista SP1, with a simple solution:
netsh winsock reset


(source, that has saved my life, and Vista to be changed to XP is: Repair and Reset Windows Vista TCP/IP Winsock Catalog Corruption... Thank you!)

Form the post and the date of the post it seems to be an error of Vista and not of SP1.

the set of errors I have had include (free translations from Spanish) :
- the client DHCP was down
- unable to start Windows Socket interface
- error with the RPC service

The reparation mechanism of Vista doesn't work because it tries to repair the the DHCP client, which is not working but for other reason.

The real reason is that the TCP/IP stack Winsock settings get corrupted with wrong LSP (Layered Service Providers (?)). No idea what this means... but you can list the catalog of LSPs with: netsh winsock show catalog.

This has been one of these few times that I find a useful solution searching for a complex problem in Internet. Thanks again to the people of My Digital Life.