Graphics Programs Reference
In-Depth Information
__weak IBOutlet UITextField *valueField;
__weak IBOutlet UILabel *dateLabel;
}
@end
If your file looks different, then your outlets aren't connected right. For instance, if you
see property declarations instead of instance variable declarations, then you let go of the
Control-drag outside of the instance variable area.
Fix any disparities between your file and the code shown above in three steps: First, go
through the Control-drag process and make connections again until you have the four
lines shown above in your DetailViewController.h . Second, remove any wrong
code (like property declarations) that got created. Finally, check for any bad connections
in the XIB file. In DetailViewController.xib , Control-click on the File's Owner .
If there are yellow warning signs next to any connection, click the x icon next to those
connections to disconnect them.
It's important to ensure there are no bad connections in a XIB file. A bad connection typ-
ically happens when you change the name of an instance variable but do not update the
connection in the XIB file. Or, you completely remove an instance variable but do not re-
move it from the XIB file. Either way, a bad connection will cause your application to
crash when the XIB file is loaded.
When you make a connection, the XIB file is supplying data at runtime to a view control-
ler. The view controller then uses this data in its existing methods to form the connection.
For example, the nameField connection is set with the following code:
[self setValue:recordedObject forKey:@"nameField"];
The setValue:forKey: method will search the receiver ( self ) for an instance vari-
able named nameField . If it can't find such a variable, an unknown key exception is
thrown.
To see the runtime error generated by a bad connection, create a new temporary outlet for
DetailViewController and connect it. Then, delete the instance variable but do not
disconnect that outlet in DetailViewController.xib . Build and run, create and
tap on a row, and then check the console as your application crashes and burns. The ex-
ception will look something like this:
'NSUnknownKeyException', reason: '
[<DetailViewController 0x68c0740> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key nameField.'
Return to the XIB and disconnect the bad outlet.
Search WWH ::




Custom Search