How to download YT videos as MP4

December 11, 2009
python yt-dl.py "http://www.yt.com/watch?v=<id_goes_here>" --format 18 --best-quality

Replace "yt" for you favorite video provider...

Custom button in navigation bar

November 8, 2009

How to create a “Settings” right bar button (only text).

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStylePlain target:self action:NULL];
self.navigationItem.rightBarButtonItem = item;
[item release];

"action" has not been set in the example.

For more details see the "Using Custom Buttons and Views as Navigation Items" section of the "View Controller Programming Guide for iPhone OS".

How to identify a text field

November 4, 2009

How do you identify a textfield if several can be received at “- (BOOL)textFieldShouldReturn:(UITextField *)textField”?

I don’t know how good it is but I did the following (I used the placeholder that the textfields have):

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if ([[textField placeholder] isEqualToString:@”Title”]) {
[textField resignFirstResponder];
[notesTextField becomeFirstResponder];
}
else if ([[textField placeholder] isEqualToString:@”Notes”]) {
[textField resignFirstResponder];
}
return YES;
}

NavigationBar application howto

November 3, 2009

The easiest way is to start with the appropriate template:

  • File -> New project -> Application -> Navigation-based Application

That will generate the app delegate and a RootViewController. The RootViewController includes a table but it can be removed and replaced by a view. Then the superclass has to be changed to UIViewController, and the File’s owner “view” outlet needs to be connected to the view.

Check that everything works.

RootViewController’s view will be the main screen of the application. In order to be accurate add a “Navigation Bar” as “Top Bar” in the “Simulated Interface Elements” of the view attributes.

Now we will generate another view and we will navigate to it.

To generate another view go to File -> New File -> Cocoa Touch Class -> UIViewController subclass. Make sure that you select “With XIB for user interface” and “Also create XxxViewController.h”.

To be able to navigate to that new view we can add a toolbar in the RootViewController’s view with a bar button. You can change the bar button identifier to “Add” to get a “+” symbol on it. Then you need to declare an action:

  • - (IBAction)newItem:(id)sender;

And implement it:

  • - (IBAction)newItem:(id)sender {
    XxxViewController *newView = [[XxxViewController alloc] initWithNibName:@”XxxViewController” bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:(UIViewController *)newView animated:YES];
    [newView release];
    }

You will need to import the “XxxViewController.h”. Also, link the action (“newItem”) with the bar button in Interface Builder.

The action will create the view controller for the second view and it will be pushed to the navigation controller. In order to get an automatic button to get back to the root view controller, the root view controller needs to have a title. Include in its “- (void)viewDidLoad” the following:

  • self.title = @”Items”;

You should be able now to use the button to go to the new view controller and the back button (“Items”) to go back to the root view controller.

Running the Clang Static Analyzer

November 2, 2009

How to:

  • Clean build in Xcode first
  • From the command line in your project directory (Clang has to be included in $PATH first): scan-build -k -V xcodebuild -configuration Debug -sdk iphonesimulator3.1
  • Results open up in Safari when completed

If your test says that the output folder has been deleted because it is empty:

  • Make sure that you include a bug (check step 5 at this other post)
  • Clean from Xcode again
  • Run scan-build again

UiTextField and resignFirstResponder.

November 2, 2009

Quick reminder on how to hide keyboard when the user hits the “return” key.

You just need to set the view controller as the delegate of the text field (it has to conform the UiTextFieldProtocol). Then call the resignFirstResponder method of the text field in the “(BOOL)textFieldShouldReturn:(UITextField *)textField” call.

Check this for a more detailed explanation and implementation code.

Deactivate iPhone’s voicemail (movistar.es)

October 30, 2009

Call 537 and select option 4.

Memory management common mistakes

October 15, 2009

I’m still starting with iPhone development and I was stuck with two very basic things, errors that will crash the application with no clue in the console:

  • Do not release “autorelease” objects. Remember that instances created using class methods that start with the name of the class are autoreleased. Using “release” on those will create problems. You only need to take care of the instances created using alloc+init, from memory management point of view
  • When working with properties it is very important to access the property using “self”, otherwise it will be accessed directly and automatic expected behaviors like “retain” or “copy” will not be there

Routing table basic operations in Mac

October 4, 2009

To see the routing table:

  • netstat -r

To add a new route:

  • Example: sudo route add -net 192.168.24 192.168.26.17

Mercurial in (Snow) Leopard: UTF-8 error

October 4, 2009

It happened to me in Leopard and Snow Leopard.

Trying to use Mercurial (hg) from the terminal I got an error complaining about UTF-8.

The solution is to include something like the following two lines in .profile (“es_ES” part corresponds to my locale, use yours):

export LC_ALL=es_ES.UTF-8

export LANG=es_ES.UTF-8


Follow

Get every new post delivered to your Inbox.