Understanding iOS Compiler Warnings – Prototype Cells Must Have Reuse Identifiers

Prototype Cells Must Have Reuse Identifiers

You will get this warning if you add a table view controller
to a storyboard. By default, a table view uses prototype cells, and since no reuse identifier has been specified immediately
after you add the table view controller, you get this warning.

To fix this problem, select the table cell (not the table view), go to the
Properties Inspector and set the Identifier
to Cell, or some other descriptive
text.

In the table view controller’s tableView:cellForRowAtIndexPath: method, you can use the identifier
to reference the cell and use it as a prototype to  create new cells. For example:

- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier
= @”CustomerCell”;

    UITableViewCell *cell =

      [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the
cell…

      CustomerEntity *customer
= [self.customer objectAtIndexPath:indexPath];

      cell.textLabel.text =
[customer.firstName

                        stringByAppendingFormat:@” %@”,
customer.lastName];

    return cell;

}

For explanations of other compiler errors and warnings, check out our new book site: http://www.iOSAppsForEveryone.com

Kevin McNeish
Eight-time .NET MVP Recipient
Apple iOS Author, Trainer
http://www.iOSAppsForEveryone.com 

FourBooks

Understanding iOS Compiler Warnings – Initializer Element Is Not a Compile-Time Constant

Initializer Element Is Not a Compile-Time Constant

You usually get this compiler error if you try to assign a
non-constant value to an instance variable. For example, you will get this
error if you place the following code outside of a class method:

NSArray *devices
= [[NSArray alloc]

                             initWithObjects:@”iPod Touch”

                             @”iPhone”,

                             @”iPad”, nil];

Although you can do this in other languages, you can’t do it in Objective-C.

To fix the problem, declare the instance variable without
initializing it:

NSArray *devices;

Then initialize the instance variable elsewhere, such as in
a view controller’s viewDidLoad
method:

- (void)viewDidLoad

{

    [super viewDidLoad];

      devices = [[NSArray
alloc]

         initWithObjects:@”iPod Touch”

         @”iPhone”,

         @”iPad”, nil];

}

For explanations of other compiler errors and warnings, check out our new book site: http://www.iOSAppsForEveryone.com

Kevin McNeish
Eight-time .NET MVP Recipient
Apple iOS Author, Trainer
http://www.iOSAppsForEveryone.com 

FourBooks

Understanding iOS Compiler Errors – Expected ‘;’ after method prototype

Expected ‘;’ after method prototype

You usually get this error in a class header file method
declaration if you forget to put a colon (not
a semicolon) before a parameter. For example, there is a colon missing after addToTotal, the method name:

- (double) addToTotal(double)value;

To fix the problem, just add a colon before the parameter:

- (double) addToTotal:(double)value;

———————————————————————————————————————————————————————-

For explanations of other compiler errors and warnings, check out our new book site: http://www.iOSAppsForEveryone.com

Kevin McNeish
Eight-time .NET MVP Recipient
Apple iOS Author, Trainer
http://www.iOSAppsForEveryone.com 

FourBooks

Understanding iOS Compiler Errors – Missing sentinel in method dispatch

Missing sentinel in method dispatch

You usually get this warning when you forget to put a nil at the end of your argument list
when calling methods such as NSArray’s
initWithObjects:

NSArray *choices = [[NSArray alloc]

                     initWithObjects:

                     @”Upper
Case”,

                     @”Lower
Case”,

                     @”Capitalized”];

 To correct this problem, just add a nil to the end of the list:

NSArray *choices = [[NSArray alloc]

                        initWithObjects:

                        @”Upper
Case”,

                        @”Lower
Case”,

                        @”Capitalized”,

                        nil];

For explanations of other compiler errors and warnings, check out our new book site: http://www.iOSAppsForEveryone.com

Kevin McNeish
Eight-time .NET MVP Recipient
Apple iOS Author, Trainer
http://www.iOSAppsForEveryone.com  FourBooks

Understanding iOS Compiler Errors – Interface type cannot be statically allocated

Interface type cannot be statically allocated

You usually get this error when you forget to include an
asterisk before a variable name this is an object pointer:

UILabel label = [[UILabel alloc] init];

To correct this problem, just add a asterisk before the
variable name:

UILabel *label =
[[UILabel alloc] init];

This is a common mistake for developers coming from other languages such as C# or Java.

For explanations of other compiler errors and warnings, check out our new book site: http://www.iOSAppsForEveryone.com

Kevin McNeish
Eight-time .NET MVP Recipient
Apple iOS Author, Trainer
http://www.iOSAppsForEveryone.com 

FourBooks

iOS App Development for Everyone

Well, it’s been a while since my last blog post, but I wanted to let all of you lurkers know I’m about 80% complete with my upcoming book “iOS App Development for Everyone”! Many of my .NET friends and associates are very interested in iOS development, so I’ll be posting information here in my MSMVP blog as well as on our book site.

This book’s intended audience is BOTH developers and non-developers. Apple’s software development tools are finally at a point where people who have never written code before can create iOS Apps.

My wife Sharlene is one of the people going through the book. She’s never written code before (except a few lines of Pascal in college), so she’s a great candidate to tell me when something needs to be explained further! This isn’t a “Dummies” book, but rather a book for smart people who haven’t written code before. Knowledgable developers can skip over the more rudimentary sections and get into the meatier topics. I think readers will find it’s the most exhaustive book written on iOS development to date (the chapter on Objective-C and the chapter on Xcode are each 200+ pages).

The book will be in printed, e-book, and iBooks 2 format (which will include videos and slide presentations). It’s been a lot of work, but a lot of fun breaking down programming principles into concepts easily understood by non-programmers.

I’ll be announcing soon a pre-sale offer for the book where interested readers can get early copies of the book so they can begin diving in!

For more information and samples of the book, check out our web site:

http://iOSAppsForEveryone.com

———————————————————————————————————————————————————————-

Kevin McNeish
Eight-time .NET MVP Recipient
Apple iOS Author, Trainer
http://www.iOSAppsForEveryone.com 

FourBooks