Entries in xCode (5)

Wednesday
Sep302009

Xcode 3.2: The New Find Redesign

One of the things that have driven me bad about Xcode was the Find dialog.  I've always felt that the find dialog got in the way and there was no way to dock to the IDE.  

Well I was pleasantly surprised to find out that when I starting using Xcode 3.2 and clicked Cmd + F to bring up the find dialog, that it did not pop up the old dialog but instead a docked version of it appeared in the IDE!  If you've used Safari, you know what I'm talking about.  It now expands  above the editor.

Here is a screen shot of my Editor before I did a find.

This is is what it looks like after I did a find:

Now what's cool is that when you enter the word your'e looking for, they are all highlighted and the first one found is highlighted in yellow.

As you can see above, all the matches are highlighted.  Now if you want to cycle between all of the found results, you can either click the arrow buttons or CMD + G to find the next result. 

Not a huge deal but this new update makes it feel like the rest of the Mac applications in Snow Leopard. I also believe this increases my productivity because I'm not messing with the dialog box, I can instantly see how many results were found!

Monday
Sep282009

Dismissing the iPhone Keyboard

For some reason a simple task like dismissing the keyboard for the iPhone can cause one to pull their hair out because it just will not work. There are a couple of key points to remember. The number #1 part developers forget to set is the delegate of the textField. If you're using the Interface Builder, remember to set the delegate of the textField to the File Owner.

 

 

 If you're not using Interface Builder, then make sure to set the delegate of the textfield to self. I also include the returnType. For example, if the textField was called gameField:

gameField.delegate = self;
gameField.returnType = UIReturnKeyDone;

 

Implement the UITextFieldDelegate Implement the UITextFieldDelegate for the ViewController is required.

@interface YourViewController : UIViewController <UITextFieldDelegate>

Finally, implement the textFieldShouldReturn method and call [textField resignFirstResponder]

- (BOOL)textFieldShouldReturn:(UITextField *)textField {{
     [textField resignFirstResponder];
     return YES;
}

 

All the textFields will use this same method, so this only needs to be setup once. Make sure the delegate is set for the textField and the UITextFieldDelegate is implemented for the interface. Finally, add the textFieldShouldReturn method and call the resignFirstResponder . That's it! Now there should not be the problem of dismissing the keyboard if these few steps are followed.

Monday
Sep282009

iPhone TableView: Swiping a cell to delete

One of the elegant features added to the iPhone mail app was the ability to swipe your finger from left to right on a tableView cell and have the delete button appear (like the right image below) to delete an item from the tableView.

 

Many people have asked me if this is possible to do for their own iPhone app.tableviewdelete 

The short answer is Yes but you have to use a couple of undocumented API calls. It's actually quiet easy. Set the cell's editingStyle to UITableViewCellEditingStyleDelete. This is an undocumented feature. Currently the documentation will show that it's a read only property. However there is nothing stopping one from setting the set property. A compiler warning like below will appear when implementing the set property.

 

 

Editing Style Warning for setting the style

To set the style, do it either in the cellForRowAtIndexPath method or implement a TableViewCell object. I'm not going to get into details of how to create a cell, I assume you already know how to do that.

- (UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
   // Add your code here to create the cell
    .....
    [cell setEditingStyle:UITableViewCellEditingStyleDelete];
}

The final set step is to actually do something when the user swipes the cell and clicks the Delete button. This is handled by adding the commitEditingStyle message to the view.

- (void)tableView:(UITableView*)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)
{
    if (editingStyle == UITableViewCellEditingStyleDelete)    {
        //Add Code to delete from the Data Source
    }
}

That's all to it. A very simple implementation for an elegant solution. I'm still miffed why this is undocumented, so be warned, you could have Apple decline your app because of the usage of an undocumented feature. UPDATE: iPhone 3.0 SDK you no longer have to set the EditingStyle of the Cell.

Monday
Sep282009

Xcode Tip: Column mode text Selecting

There are times when you need to select text in column mode instead of the tradtional row selection. Think of it like selecting a range of columns in a spreadsheet like Excel or Numbers. For example, lets say there is 4 members that you want to make into properties. Text to Highlight

Move the cursor to the beginning column you want to start highlighting from. Hold down the ALT/Otption key and then press and hold down the left mouse button. Next, highlight the code with the mouse or arrow keys. After the code is highlighted, simply copy it to the clipboard. (command + C Key)

Highlighted Text

Notice in the image above, I previously pasted the @property four (4) times so that I could then insert the selected code once. To do this, move the cursor to the position of the first @property and paste. (Command + V).

Text Pasted There you go! The columns of code that were highlighted and saved to the clipboard are now pasted all at once. No need to have to paste each variable one at a time!

ALT + Left Mouse button = Column Mode Text Selection

Monday
Sep282009

Developing under OSX 10.6 and Xcode 3.2

Snow leopard at first glace did not seem like an upgrade worth buying because not much as changed as far as the presentation and new features.  However after using it you can really tell the work was done to internals of the OS.  What has also impressed me is the new Xcode 3.2 that works only in Snow Leopard.  Apple has done a fine job at bringing this Development IDE to the level of Visual Studio.  When I first started doing some development on OSX, Xcode was no where near the development IDE of Visual Studio.  However that is all changed.

Time to upgrade all the other mac's here at Agilite because once you start using Snow Leopard, you quickly realize it and start looking for the things you've started taken for granted when using Snow Leopard.

If your a Mac or iPhone developer, I highly recommend that you get out to your local Apple store and purchase Snow Leopard just for the upgrade of Xcode alone.  For $49 for the family pack, you can't go wrong!