Tech and a few other things RSS 2.0
# Monday, May 23, 2011


Code:
NSUInteger       newIndex[]   = {0, row};
NSIndexPath	*newPath      = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
There is quite a few things assumed in these 2 simple lines of code. Let's break it down into newbie terms.

First you must understand that a "section" is an area of grouped rows in a tableview. You see this in many iPhone apps. Think about the "Settings" app. Click around in it and you will see sections.

Next you must understand that a tableview assigns the property "cellForRowAtIndexPath" with a NSIndexPath value. In short this property looks at the NSIndexPath's first value for the section the row is in and then the second value for the row itself for the value you are trying to retrieve. 

The 0 in the "newIndex[]" is for the "section" in the tableview, stating this will be the 1st section (in this case the only section). and the "row" is for the...well row in the section within the tableview.

So in the next next line with "*newPath" you have the code assigning the "newIndex" with a "length" of 2. What you are reading here is that tableview should look two nodes deep in your array of sections with each node in your section array caring an array of row nodes (think nested arrays).

The first node is the section array and the second node is the row.
So in our example:
Node 1 = specific node in section array (here its node 0), 
Node 2 = specific node in row array nested in Section array.


If the above is italicized text is confusing see screen shot I attached. The picture may make it easier to understand. Array 0 is the array of section nodes, where each section node contains an array of rows.





An different way to create the NSIndexPath that might be easier to read is to use this function.
Code:
NSIndexPath *myPath = [NSIndexPath indexPathForRow:myRow inSection:mySelction];
Here is the exact definition from Apple Documentation, with the knowledge I gave you above it should be a bit more clear now. A "category" by the way, is, in short, a way to add extra methods to a class without subclassing it.

Many methods of UITableViewDelegate take NSIndexPath objects as parameters and return values. UITableView declares a category on NSIndexPath that enables you to get the represented row index (row property) and section index (section property), and to construct an index path from a given row index and section index (indexPathForRow:inSection: method). Because rows are located within their sections, you usually must evaluate the section index number before you can identify the row by its index number

Monday, May 23, 2011 4:38:30 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Objective C | xCode
# Sunday, February 27, 2011


Have you ever seen a silk teddy bear. They're nice, soft, smooth and comforting. They take something scary and unmanageable like a grizzly bear, and make the animal manageable, gentle and silky smooth.

In the just-released Beginning iPhone 4 Development, authors Jeff LaMarche and David Mark team up with Jack Nutting to take the ever-growing and changing iOS and break it down into manageable chunks. In this informative and light-hearted read, the authors bring the new edition with updates to key subjects like Core Data, Grand Central Dispatch and iPad/iPod programming specifics. Full of step-by-step instructions and intuitive pictures, Beginning iPhone 4 Development serves as a perfect guide for the novice yet remains effective as a quick reference to the experienced developer. In the end it's all about having fun, making an app you want and not about getting frustrated at trying to understand the idiosyncrasies of iOS. With their latest offering, LaMarche, Mark and Nutting get you on the right path.

Sunday, February 27, 2011 1:33:35 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iphone | iphone | Objective C | readings | xCode
# Sunday, February 13, 2011


Problem:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Popovers cannot be presented from a UIBarButtonItem that is not in a toolbar or navigation bar already.'

Solution:
You can get the error for a number of reasons, but I'm betting it's because you didn't declare your UIBarButtonItem correctly in either your header file or your implementation file. You might have done something like this in your header file.

@interface TestInterface : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate>
{
    UIButtonItem    *button
}

@property (nonatomic, retain) IBOutlet UIBarButtonItem *Button;


Notice the Button variable is declared with one "B" capitalized and the other "b" is not.

And then in your implementation file you tried to call the button by using the non-capitalized declaration.
Like so:
[poc presentPopoverFramBarButtonItem:button ...];

Explanation:
Usually what causes this is, what I would consider, but technically is not, a syntax error. You tried to call a variable that doesn't exist, kinda. The real kicker is there is no compile error. Which is correct, as you should be able to declare code as such in the header file, it just makes it easy for the user to reference the incorrect variable name.

Sunday, February 13, 2011 11:10:30 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iPad | Objective C | xCode
# Tuesday, November 23, 2010


Problem:

error: expected '=', ',', ';', 'asm' or '__attribute__' before '>' token

Solution:
You didn't close your "<" or ">" when implementing a protocol. Take a peak, I bet that is it.

Example:
@interface YouRock : UIViewController UITableViewDelegate, UITableViewDataSource>    <-- Notice the missing "<" in front of UITableViewDelegate

Explanation:
Syntax, they are the easiest errors to fix. You should have got this, but guess what I did the same damn thing.

Tuesday, November 23, 2010 8:32:17 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Mac | xCode


You want to know a good Diff application for the Mac. Well you are in luck, there is one bundled with xCode. It's called FileMerge, so you know what to do from here right. No? I'll tell you. Hit that Mother F#cking (apple)command-spacebar to bring up spotlight and type "FileMerge." If you have it, it will show up right at the top. Now hit enter, go on, hit it. Now didn't that feel nice. Welcome to the world of FileMerge.

Coffman out! <-- My tribute to Californication.

Tuesday, November 23, 2010 8:23:30 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Mac | xCode
# Saturday, September 04, 2010



I'm done! After a summer of surprises, swings, and roadblocks I finally finished this book, a few months behind schedule, but it's done. The last objective-C book I read was by the de facto in Mac OS X development Mr. Hillegass, (my post) I embarked on the journey of reading a book on iPhone development with the man in iPhone teaching Jeff LaMarche. Jeff is every bit as good at breaking down complex topics and making them seem easy as my .Net home skillet Scott Hanselman. In short these dudes are just smart, but they'll never tell you that and they write some good books.

This book is an easy read and provides hands on examples on how to use many of the tools provided with the iPhone SDK 3. The book is spot on with it's examples, but I'm betting new Objective-C users might have trouble following along when  xCode 4 comes out. xCode 4 is quite a bit different graphically than 3 and may render the step by step instructions in this book out of date.

Overall if you are into programming on the iPhone, this is a great book to start, given you have a base working knowledge of Objective-C and an advanced understanding of programming in general.

 

Saturday, September 04, 2010 3:29:55 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iphone | iphone | Objective C | readings | xCode
# Wednesday, September 01, 2010


Error Readout:

error: expected '=', ',', ';', 'asm' or '__attribute__' before 'interface'

Fix:
Added a semicolon.

Explanation:
It's important to remember that this was occurring before the interface tag, which meant it was happening in a file I was importing. In this case it was a header file with an enumeration in it that were not showing an error with a missing semi colon.


Wednesday, September 01, 2010 3:54:31 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iphone | Objective C | xCode
# Sunday, June 06, 2010

When starting a new project you have the ability to  select a template of premade projects. Two examples of this are
    1. Navigation Based Application
    2. View Based application

When these templates are selected xCode will create the appropriate base controller for you in interface builder, such as "Navigation Controller" or a "View Controller" it will also create the appropriate classes for you with some of the most commonly used delegate and datasource methods along with the appropriate methods to override.

With a new project and selecting Window-based application, you are simply creating a blank slate in which you have to create nearly everything. It's rarely advantageous to use this unless, you are creating something outside the templates offered or you are learning how all the pieces fit together.

Sunday, June 06, 2010 7:05:58 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Objective C | xCode
# Sunday, May 09, 2010

The Problem:
I was getting a white screen with no data in a UITableView on it in the iPhone simulator.

The Solution:
I had my initialization code for the array in the the "loadView" method and not the "viewDidLoad" method

Explanation:
Don't read self.view in -loadView. Only set it, don't get it. The self.view property accessor calls -loadView if the view isn't currently loaded. There's your infinite recursion. I'm guessing UITableView calls a View [pretty good guess since "view" is in the name. :)] which in turn caused my recursion.

This was a stupid little error that caused me about 30 minutes of my life due to the fact I didn't get any build errors. A simple copy and paste moved me forward.

Update: I think it might be important to distinguish the differece between loadView and viewDidLoad. (below)

loadView is the method in UIViewController that will actually load up the view and assign it to the "view" property. This is also the location that a subclass of UIViewController would override if you wanted to programatically set up the "view" property. viewDidLoad is the method that is called once the view has been loaded. This is called after loadView is called. It is a place where you can override and insert code that does further initial setup of the view once it has been loaded.

Sunday, May 09, 2010 5:55:43 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iphone | Objective C | xCode
# Tuesday, April 13, 2010

I'll keep this post short. I read this book to prepare myself for iPhone development and give me a deeper understanding of Objective C. This book is probably the best book to start learning Cocoa Programming currently on the market. It gives chapter by chapter examples with exercises to follow along with. The only shortcoming of the book is that it's a bit dated to what the current xCode version is. A few of the examples might take the novice for a spin (which means it took me for a spin, sometimes a quite frustrating spin) because the step by step instructions are not exactly correct due to the fact some of the menu items have changed or been rearranged. Outside of a few minor issues, like the one I mentioned earlier, it's a pretty fun book and I would recommend it to other experienced programmers. Hopefully Mr. Hillegass will come out with a newer version.












Things covered in the book

Memory Management
Target/Actions
Helper Objects
Key-Value Coding; Key-Value Observing
NSArrayController
NSUndoManager
Archiving
Basic Core Data
Nib Files and NSWindowController
User Defaults
Using Notifications
Using Alert Panels
Localization

The list keeps going, it really covers all you need to know for having a strong hold on the basics.

Tuesday, April 13, 2010 9:10:59 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Mac OS X | Objective C | readings | xCode
# Tuesday, March 09, 2010


Error Readout:
error: A valid signing identity matching this profile could not be found in  your keychain

The Problem:

In Keychain Access it reads the error above.

The Solution:

This can be cause by several issues. The highest probability is, you didn't install the certificate you created in the distribution or development page of "certificates" in the iPhone Provisioning Portal.
Tuesday, March 09, 2010 9:37:21 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
App Store | iphone | xCode


Error Readout:
Code Sign error: The identity 'iPhone Distribution' doesn't match any valid certificate/private key pair in the default keychain

The Problem:

I try and build my application and I get the error above

The Solution:
Many things can cause this error. The error is probably caused by one of the steps being done incorrectly in the Program User Guide. Most won't like reading this, but the best way to fix this is to go back and follow, very precisely, the steps in "Program User Guide." In case the link changes you can get to the pdf by going to http://developer.apple.com/iphone, logging in, clicking "iPhone Provisioning Profile" and in the box on the left hand side of the screen titled "Provisioning Resources," you can download the Program User Guide pdf.

Explanation:
Yes, we ALL wish this process could be more streamlined, and require less reading, but it doesn't. If you want to get that app out there, suck it up, read the 60 pages [lots of pictures :) ] and be done with it.
Tuesday, March 09, 2010 9:14:18 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
App Store | iphone | xCode
# Saturday, February 27, 2010
Making an iPhone icon is way easier than I had anticipated. You don't need to round the corners, you don't have to give it the little glow as if the sun is shining down upon it. Simply make your icon in a 57x57 png and the iPhone SDK does the rest for you. Here is a link to some good apple documentation on making an iPhone Icon. See the icon I created below (1) and the icon that showed up once I plugged the image into xcode (2).


1.             2.

     
 

Saturday, February 27, 2010 9:41:41 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iphone | xCode
Navigation
About the author/Disclaimer
        

My name is Ben Coffman. I like to build things: programs, programming teams, programming departments and maybe one day a company with lots of programmers. When I turn the internet off I focus on my family, random hobbies, and sharing moments in life.

Blogs I follow:

1. 2andahalfd.com

2. Jeff Lamarche

3. Scott Hanselman

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Ben Coffman

Archive
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
All Content © 2012,

Sign In