Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed error with CFAutorelease in ABContact

  • Loading branch information...
commit 1fb049de3676cafa9e4e8a8469ed3adadbaca631 1 parent 5e074ed
Erica Sadun authored
8 C11-Tables/16-Searching Tables/main.m
@@ -38,6 +38,12 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
38 38 return 1;
39 39 }
40 40
  41 +// Via Jack Lucky
  42 +- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  43 +{
  44 + [self.searchBar setText:@""];
  45 +}
  46 +
41 47 - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
42 48 {
43 49 // Normal table
@@ -97,7 +103,7 @@ - (void) viewDidLoad
97 103 {
98 104 // Prepare the crayon color dictionary
99 105 NSString *pathname = [[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt" inDirectory:@"/"];
100   - NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname] componentsSeparatedByString:@"\n"];
  106 + NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString:@"\n"];
101 107 self.crayonColors = [NSMutableDictionary dictionary];
102 108 for (NSString *string in rawCrayons)
103 109 [self.crayonColors setObject:CRAYON_COLOR(string) forKey:CRAYON_NAME(string)];
8 C11-Tables/17-Adding Headers and an Index/main.m
@@ -44,6 +44,12 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
44 44 return 1;
45 45 }
46 46
  47 +// Via Jack Lucky
  48 +- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  49 +{
  50 + [self.searchBar setText:@""];
  51 +}
  52 +
47 53 - (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section
48 54 {
49 55 if (aTableView == self.tableView)
@@ -145,7 +151,7 @@ - (void) viewDidLoad
145 151 {
146 152 // Prepare the crayon color dictionary
147 153 NSString *pathname = [[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt" inDirectory:@"/"];
148   - NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname] componentsSeparatedByString:@"\n"];
  154 + NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString:@"\n"];
149 155 self.crayonColors = [NSMutableDictionary dictionary];
150 156
151 157 self.sectionArray = [NSMutableArray array];
8 C11-Tables/18-Grouped Tables/main.m
@@ -50,6 +50,12 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
50 50 return 1;
51 51 }
52 52
  53 +// Via Jack Lucky
  54 +- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  55 +{
  56 + [self.searchBar setText:@""];
  57 +}
  58 +
53 59 - (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section
54 60 {
55 61 if (aTableView == self.tableView)
@@ -150,7 +156,7 @@ - (void) viewDidLoad
150 156 {
151 157 // Prepare the crayon color dictionary
152 158 NSString *pathname = [[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt" inDirectory:@"/"];
153   - NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname] componentsSeparatedByString:@"\n"];
  159 + NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString:@"\n"];
154 160 self.crayonColors = [NSMutableDictionary dictionary];
155 161
156 162 self.sectionArray = [NSMutableArray array];
8 C11-Tables/19-Headers and Footers/main.m
@@ -54,6 +54,12 @@ - (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInt
54 54 else return nil;
55 55 }
56 56
  57 +// Via Jack Lucky
  58 +- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  59 +{
  60 + [self.searchBar setText:@""];
  61 +}
  62 +
57 63 - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
58 64 {
59 65 // Normal table
@@ -148,7 +154,7 @@ - (void) viewDidLoad
148 154 {
149 155 // Prepare the crayon color dictionary
150 156 NSString *pathname = [[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt" inDirectory:@"/"];
151   - NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname] componentsSeparatedByString:@"\n"];
  157 + NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString:@"\n"];
152 158 self.crayonColors = [NSMutableDictionary dictionary];
153 159
154 160 self.sectionArray = [NSMutableArray array];
2  C18-Address Book/02-Display Contact/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
24 24
25 25 + (id) contactWithRecordID: (ABRecordID) recordID
26 26 {
27   - ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
  27 + ABAddressBookRef addressBook = ABAddressBookCreate();
28 28 ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
29 29 ABContact *contact = [self contactWithRecord:contactrec];
30 30 // CFRelease(contactrec); // Thanks Gary Fung
6 C18-Address Book/02-Display Contact/main.m
@@ -44,6 +44,12 @@ - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSIntege
44 44 return self.filteredArray.count;
45 45 }
46 46
  47 +// Via Jack Lucky
  48 +- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  49 +{
  50 + [self.searchBar setText:@""];
  51 +}
  52 +
47 53 - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
48 54 {
49 55 // Dequeue or create a cell
2  C18-Address Book/03-Images/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
24 24
25 25 + (id) contactWithRecordID: (ABRecordID) recordID
26 26 {
27   - ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
  27 + ABAddressBookRef addressBook = ABAddressBookCreate();
28 28 ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
29 29 ABContact *contact = [self contactWithRecord:contactrec];
30 30 // CFRelease(contactrec); // Thanks Gary Fung
2  C18-Address Book/04-People Picker/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
24 24
25 25 + (id) contactWithRecordID: (ABRecordID) recordID
26 26 {
27   - ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
  27 + ABAddressBookRef addressBook = ABAddressBookCreate();
28 28 ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
29 29 ABContact *contact = [self contactWithRecord:contactrec];
30 30 // CFRelease(contactrec); // Thanks Gary Fung
2  C18-Address Book/04b-Property Picker/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
24 24
25 25 + (id) contactWithRecordID: (ABRecordID) recordID
26 26 {
27   - ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
  27 + ABAddressBookRef addressBook = ABAddressBookCreate();
28 28 ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
29 29 ABContact *contact = [self contactWithRecord:contactrec];
30 30 // CFRelease(contactrec); // Thanks Gary Fung
2  C18-Address Book/05-Type Picker/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
24 24
25 25 + (id) contactWithRecordID: (ABRecordID) recordID
26 26 {
27   - ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
  27 + ABAddressBookRef addressBook = ABAddressBookCreate();
28 28 ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
29 29 ABContact *contact = [self contactWithRecord:contactrec];
30 30 // CFRelease(contactrec); // Thanks Gary Fung
2  C18-Address Book/06-New Contact/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
24 24
25 25 + (id) contactWithRecordID: (ABRecordID) recordID
26 26 {
27   - ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
  27 + ABAddressBookRef addressBook = ABAddressBookCreate();
28 28 ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
29 29 ABContact *contact = [self contactWithRecord:contactrec];
30 30 // CFRelease(contactrec); // Thanks Gary Fung
2  C18-Address Book/07-Modifying Contact/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
24 24
25 25 + (id) contactWithRecordID: (ABRecordID) recordID
26 26 {
27   - ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
  27 + ABAddressBookRef addressBook = ABAddressBookCreate();
28 28 ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
29 29 ABContact *contact = [self contactWithRecord:contactrec];
30 30 // CFRelease(contactrec); // Thanks Gary Fung
2  C18-Address Book/08-Unknown Controller/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
24 24
25 25 + (id) contactWithRecordID: (ABRecordID) recordID
26 26 {
27   - ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
  27 + ABAddressBookRef addressBook = ABAddressBookCreate();
28 28 ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
29 29 ABContact *contact = [self contactWithRecord:contactrec];
30 30 // CFRelease(contactrec); // Thanks Gary Fung
2  C18-Address Book/09-Monsters/ABContact.m
@@ -24,7 +24,7 @@ + (id) contactWithRecord: (ABRecordRef) person
24 24
25 25 + (id) contactWithRecordID: (ABRecordID) recordID
26 26 {
27   - ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
  27 + ABAddressBookRef addressBook = ABAddressBookCreate();
28 28 ABRecordRef contactrec = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
29 29 ABContact *contact = [self contactWithRecord:contactrec];
30 30 // CFRelease(contactrec); // Thanks Gary Fung
19 C19-CoreData/02-Queried Color List/main.m
@@ -191,7 +191,24 @@ - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSS
191 191
192 192 #pragma mark Search Bar
193 193
194   -// Cancel button fix provided by jluckyiv.
  194 +/*
  195 +Cancel button fix suggested by Jack Lucky, who writes:
  196 +
  197 +"After some more research, I think my solution was really a workaround. After reading the documentation for
  198 + UISearchDisplayController, I think the problem is that when tableView:numberOfRowsInSection: fires, there is a
  199 + disconnect between it and [tableView reload]... Here's my approach:
  200 +
  201 +- (void)refreshTableView {
  202 + [self performFetch];
  203 + if (searchBar.text && searchBar.text.length) {
  204 + [self.searchDC.searchResultsTableView reloadData];
  205 + } else {
  206 + [self.tableView reloadData];
  207 + }
  208 +}
  209 + "
  210 + */
  211 +
195 212 - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
196 213 {
197 214 [self.searchBar setText:@""];

0 comments on commit 1fb049d

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