Skip to content
Browse files

Fixed error with CFAutorelease in ABContact

  • Loading branch information...
1 parent 5e074ed commit 1fb049de3676cafa9e4e8a8469ed3adadbaca631 Erica Sadun committed Dec 3, 2009
View
8 C11-Tables/16-Searching Tables/main.m
@@ -38,6 +38,12 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
return 1;
}
+// Via Jack Lucky
+- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
+{
+ [self.searchBar setText:@""];
+}
+
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
// Normal table
@@ -97,7 +103,7 @@ - (void) viewDidLoad
{
// Prepare the crayon color dictionary
NSString *pathname = [[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt" inDirectory:@"/"];
- NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname] componentsSeparatedByString:@"\n"];
+ NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString:@"\n"];
self.crayonColors = [NSMutableDictionary dictionary];
for (NSString *string in rawCrayons)
[self.crayonColors setObject:CRAYON_COLOR(string) forKey:CRAYON_NAME(string)];
View
8 C11-Tables/17-Adding Headers and an Index/main.m
@@ -44,6 +44,12 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
return 1;
}
+// Via Jack Lucky
+- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
+{
+ [self.searchBar setText:@""];
+}
+
- (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section
{
if (aTableView == self.tableView)
@@ -145,7 +151,7 @@ - (void) viewDidLoad
{
// Prepare the crayon color dictionary
NSString *pathname = [[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt" inDirectory:@"/"];
- NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname] componentsSeparatedByString:@"\n"];
+ NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString:@"\n"];
self.crayonColors = [NSMutableDictionary dictionary];
self.sectionArray = [NSMutableArray array];
View
8 C11-Tables/18-Grouped Tables/main.m
@@ -50,6 +50,12 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
return 1;
}
+// Via Jack Lucky
+- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
+{
+ [self.searchBar setText:@""];
+}
+
- (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section
{
if (aTableView == self.tableView)
@@ -150,7 +156,7 @@ - (void) viewDidLoad
{
// Prepare the crayon color dictionary
NSString *pathname = [[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt" inDirectory:@"/"];
- NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname] componentsSeparatedByString:@"\n"];
+ NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString:@"\n"];
self.crayonColors = [NSMutableDictionary dictionary];
self.sectionArray = [NSMutableArray array];
View
8 C11-Tables/19-Headers and Footers/main.m
@@ -54,6 +54,12 @@ - (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInt
else return nil;
}
+// Via Jack Lucky
+- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
+{
+ [self.searchBar setText:@""];
+}
+
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
// Normal table
@@ -148,7 +154,7 @@ - (void) viewDidLoad
{
// Prepare the crayon color dictionary
NSString *pathname = [[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt" inDirectory:@"/"];
- NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname] componentsSeparatedByString:@"\n"];
+ NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString:@"\n"];
self.crayonColors = [NSMutableDictionary dictionary];
self.sectionArray = [NSMutableArray array];
View
2 C18-Address Book/02-Display Contact/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
+ (id) contactWithRecordID: (ABRecordID) recordID
{
- ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
+ ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
ABContact *contact = [self contactWithRecord:contactrec];
// CFRelease(contactrec); // Thanks Gary Fung
View
6 C18-Address Book/02-Display Contact/main.m
@@ -44,6 +44,12 @@ - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSIntege
return self.filteredArray.count;
}
+// Via Jack Lucky
+- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
+{
+ [self.searchBar setText:@""];
+}
+
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Dequeue or create a cell
View
2 C18-Address Book/03-Images/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
+ (id) contactWithRecordID: (ABRecordID) recordID
{
- ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
+ ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
ABContact *contact = [self contactWithRecord:contactrec];
// CFRelease(contactrec); // Thanks Gary Fung
View
2 C18-Address Book/04-People Picker/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
+ (id) contactWithRecordID: (ABRecordID) recordID
{
- ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
+ ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
ABContact *contact = [self contactWithRecord:contactrec];
// CFRelease(contactrec); // Thanks Gary Fung
View
2 C18-Address Book/04b-Property Picker/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
+ (id) contactWithRecordID: (ABRecordID) recordID
{
- ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
+ ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
ABContact *contact = [self contactWithRecord:contactrec];
// CFRelease(contactrec); // Thanks Gary Fung
View
2 C18-Address Book/05-Type Picker/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
+ (id) contactWithRecordID: (ABRecordID) recordID
{
- ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
+ ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
ABContact *contact = [self contactWithRecord:contactrec];
// CFRelease(contactrec); // Thanks Gary Fung
View
2 C18-Address Book/06-New Contact/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
+ (id) contactWithRecordID: (ABRecordID) recordID
{
- ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
+ ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
ABContact *contact = [self contactWithRecord:contactrec];
// CFRelease(contactrec); // Thanks Gary Fung
View
2 C18-Address Book/07-Modifying Contact/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
+ (id) contactWithRecordID: (ABRecordID) recordID
{
- ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
+ ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
ABContact *contact = [self contactWithRecord:contactrec];
// CFRelease(contactrec); // Thanks Gary Fung
View
2 C18-Address Book/08-Unknown Controller/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
+ (id) contactWithRecordID: (ABRecordID) recordID
{
- ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
+ ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
ABContact *contact = [self contactWithRecord:contactrec];
// CFRelease(contactrec); // Thanks Gary Fung
View
2 C18-Address Book/09-Monsters/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
+ (id) contactWithRecordID: (ABRecordID) recordID
{
- ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
+ ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
ABContact *contact = [self contactWithRecord:contactrec];
// CFRelease(contactrec); // Thanks Gary Fung
View
19 C19-CoreData/02-Queried Color List/main.m
@@ -191,7 +191,24 @@ - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSS
#pragma mark Search Bar
-// Cancel button fix provided by jluckyiv.
+/*
+Cancel button fix suggested by Jack Lucky, who writes:
+
+"After some more research, I think my solution was really a workaround. After reading the documentation for
+ UISearchDisplayController, I think the problem is that when tableView:numberOfRowsInSection: fires, there is a
+ disconnect between it and [tableView reload]... Here's my approach:
+
+- (void)refreshTableView {
+ [self performFetch];
+ if (searchBar.text && searchBar.text.length) {
+ [self.searchDC.searchResultsTableView reloadData];
+ } else {
+ [self.tableView reloadData];
+ }
+}
+ "
+ */
+
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
[self.searchBar setText:@""];

0 comments on commit 1fb049d

Please sign in to comment.
Something went wrong with that request. Please try again.