June 2012 - Posts
0
0
1
175
1002
Oak Leaf Enterprises, Inc
8
2
1175
14.0
Normal
0
false
false
false
false
EN-US
JA
X-NONE
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
0
0
1
107
612
Oak Leaf Enterprises, Inc
5
1
718
14.0
Normal
0
false
false
false
EN-US
JA
X-NONE
You typically get this error when there is a problem with
one of your outlets. One of the most common reasons for this error is creating
an outlet on a custom table view cell, which isn’t allowed in Xcode. For
details, see Chapter 6: Managing Lists of
Data With Table Views under the section Creating
Custom Cells. To find out exactly what’s wrong, do the following:
1.
Build the project so the compiler error appears
2.
In the navigator pane (on the left side of the
Xcode window) select the Log Navigator from navigator toolbar (the last button
on the right). You can also display the Log Navigator by pressing Command+7.
3.
Select the Build
item at the top of the list. This displays log detail on the right (Figure A-1).
0
0
1
49
285
Oak Leaf Enterprises, Inc
2
1
333
14.0
Normal
0
false
false
false
false
EN-US
JA
X-NONE
![]()
Figure A-1: The Log Navigator
displays compiler error details
4. To see detailed information for a particular
item, click the white oval button to the far right of the item (Figure A-2). This usually gives you
enough information to figure out what’s wrong.
![]()
Figure A-2: Click the log detail
button for details on a particular log item
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
0
0
1
106
610
Oak Leaf Enterprises, Inc
5
1
715
14.0
Normal
0
false
false
false
EN-US
JA
X-NONE
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
0
0
1
46
266
Oak Leaf Enterprises, Inc
2
1
311
14.0
Normal
0
false
false
false
EN-US
JA
X-NONE
Property access result unused – getters should not be used for side effects
If you try to call a method that takes no arguments using
dot notation (rather than passing a message), you will get this warning. For
example:
self.clear;
To fix this warning, change the code to pass a message
instead:
[self clear];
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
0
0
1
51
292
Oak Leaf Enterprises, Inc
2
1
342
14.0
Normal
0
false
false
false
EN-US
JA
X-NONE
0
0
1
5
32
Oak Leaf Enterprises, Inc
1
1
36
14.0
Normal
0
false
false
false
EN-US
JA
X-NONE
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
0
0
1
77
443
Oak Leaf Enterprises, Inc
3
1
519
14.0
Normal
0
false
false
false
EN-US
JA
X-NONE
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
0
0
1
47
269
Oak Leaf Enterprises, Inc
2
1
315
14.0
Normal
0
false
false
false
EN-US
JA
X-NONE
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
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