|
|
#1 |
|
kayboard hide when reload table
I created a subClass of UITextView with a searchBar, here is the code:
Code:
#import "SezioniTableController.h"
@interface SezioniTableController ()
@end
@implementation SezioniTableController
@synthesize searchBar,searchDisplayController;
@synthesize arraySezioni,arrayFiltrato;
@synthesize objTesto;
- (id)initWithStyle:(UITableViewStyle)style andArray:(NSMutableArray *)array{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
self.searchBar.delegate = self;
self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
self.searchDisplayController.delegate = self;
self.searchDisplayController.searchResultsDataSource = self;
self.arraySezioni = array;
self.arrayFiltrato = array;
}
return self;
}
- (void) didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) loadView {}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return self.arrayFiltrato.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewStylePlain reuseIdentifier:@"MyIdentifier"];
}
NSLog(@"Array count:%d",self.arraySezioni.count);
self.objTesto = [arrayFiltrato objectAtIndex:indexPath.row];
cell.textLabel.text = self.objTesto.titoloTesto;
return cell;
}
#pragma mark - Table view delegate
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *dict = [NSDictionary dictionaryWithObject:[self.arrayFiltrato objectAtIndex:indexPath.row] forKey:@"Testo"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"PassaggioTesto" object:self userInfo:dict];
NSLog(@"Click");
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return self.searchBar;
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 44;
}
- (BOOL) searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{
[self filterContentForSearchText:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
NSLog(@"shouldReloadTableForSearchString");
//[[NSNotificationCenter defaultCenter] postNotificationName:@"ReloadTable" object:self];
// Return YES to cause the search result table view to be reloaded.
return YES;
}
- (BOOL) searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption{
[self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
NSLog(@"shouldReloadTableForSearchScope");
//[[NSNotificationCenter defaultCenter] postNotificationName:@"ReloadTable" object:self];
// Return YES to cause the search result table view to be reloaded.
return YES;
}
- (void) filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope{
self.arrayFiltrato = [[NSMutableArray alloc] init];
NSLog(@"Array count:%d",self.arraySezioni.count);
for (objTesto in self.arraySezioni){
NSComparisonResult result = [objTesto.titoloTesto compare:searchText options:NSCaseInsensitiveSearch range:NSMakeRange(0, [searchText length])];
NSLog(@"Titolo: %@ search: %@",objTesto.titoloTesto,searchText);
if (result == NSOrderedSame){
NSLog(@"Si");
[self.arrayFiltrato addObject:objTesto];
}else{
NSLog(@"no");
}
}
NSLog(@"Array count:%d",self.arrayFiltrato.count);
}
- (void) searchBarCancelButtonClicked:(UISearchBar *)saearchBar {
[self.arrayFiltrato removeAllObjects];
self.arrayFiltrato = self.arraySezioni;
}
@end
Code:
int tag = [sender tag];
self.arrayTesti = [self.dataLoad leggiArgomentiDellaSezione:tag];
self.table = [[SezioniTableController alloc] initWithStyle:UITableViewStylePlain andArray:self.arrayTesti];
self.tableArgumentView.delegate = self.table;
self.tableArgumentView.dataSource = self.table;
[self.tableArgumentView reloadData];
- (void) reload {
[self.tableArgumentView reloadData];
}
Where is the problem for you?
__________________
iTouch 1G |
|
|
|
0
|
|
|
#2 |
|
It looks to me like your issue might have to do with the fact that your search bar is contained in the header row of the UITableView... thus, each time it reloads data, it destroys the search bar that is active, and then creates a new one in the exact same spot.
That's just a theory. If that is the problem, then a possible workaround would be automatically selecting the new search bar as soon as it's created.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed. Like it on Facebook! |
|
|
|
0
|
|
|
#3 |
|
I have notice that I if add on the init method a view:
Code:
UITableView *newTableView = [[UITableView alloc] initWithFrame:rect style:UITableViewStylePlain]; self.view = newTableView; self.tableView = newTableView; Code:
[self.bottomView addSubview:self.table.view];
__________________
iTouch 1G |
|
|
|
0
|
|
|
#4 |
|
If you're using ARC, you probably won't get a memory issue. But, initing and adding subview every time your tableview data changes certainly seems like overkill. You should look closer into how your are resigning responders when your searchBar is being used.
__________________
|
|
|
|
0
|
|
|
#5 | |
|
Quote:
for memory issue I mean a lot of memory usage, for solve the problem of re-init and re-addsub view of my table may be sufficient add Code:
if (self.table) {
self.table=nil;
[self.table.tableview removefromsuperview];
}
kikko088
__________________
iTouch 1G |
||
|
|
0
|
|
|
#6 |
|
Seems to me you are trying to cure the wrong symptom and now adding code to complicate matters. Having the keyboard dismiss properly should not require recreating entire tables. Remove that code and go back and look at the original issue closely. What is the code that is running when you enter characters in the searchBar? Use breakpoints and step-through the code, if necessary, to understand what is being executed. Using this technique you can hopefully start to hone in on the real issue.
__________________
|
|
|
|
0
|
|
|
#7 |
|
dear dejo, my english does not allow me to explain myself well.
Originally the problem was that when I try to search a word after every character the keyboard dismiss. In this situation I creat an UITableView on my UIVIewController and setting Delegate and Datasource of the UITableView on my UIViewController like the code below Code:
self.table = [[SezioniTableController alloc] initWithStyle:UITableViewStylePlain andArray:self.arrayTesti]; self.tableArgumentView.delegate = self.table; self.tableArgumentView.dataSource = self.table; [self.tableArgumentView reloadData]; the first is to add a UITableView on my UITableViewController and set Delegate and DataSource of this new table directly on UITableViewController instead on UIViewController, in this situation I init theUITableViewController when I have to populate the table (not when I try to search something) and all work fine. My doubt for re-init and re-addsubview is that the table can change data, for example, I have 5 button that do an action for populate the UITableViewController, every time I click the button I re-init the table and addsubview, I think that is better change the array of table and ReloadData of the table but not work, so I have to re-init and re-addsub view of my UITableViewController. I hope I explained.
__________________
iTouch 1G |
|
|
|
0
|
|
|
#8 |
|
Yes, and this issue has still not been corrected, right? If not, concentrate on that.
__________________
|
|
|
|
0
|
|
|
#9 |
|
no no the problem has now been fixed, all work fine!
I have only the dubt if re-init mt table every time I change the data is incorrect.edit: no is not true that all work, after search didSelectRowAtIndexPath not work, one moment that I try to find the error , when I found it and correct it I update the thread
__________________
iTouch 1G Last edited by kikko088; Nov 12, 2012 at 01:17 PM. |
|
|
|
0
|
|
|
#10 | |
|
Quote:
P.S. Then, in the future, you should consider starting a separate thread for such a separate issue as your table initing concerns.
__________________
|
||
|
|
0
|
|
|
#11 | |
|
Quote:
I think there is some problem with this table...then now I try to debug it but I want to ask your help for some input. The table work fine unless I search something...If I search something the table was reloaded with the correct filtered array but if I click on one row didSelectRowAtIndexPath isn't called. if I set: self.searchDisplayController.searchResultsDelegate = self; when I init the searchdisplaycontroller after one character uisearchbar move down and after two character kayboard was dismiss, but the row work correctly. I try to debug the error but without good result, can you help me only with some input of where I have to see? kikko088
__________________
iTouch 1G Last edited by kikko088; Nov 12, 2012 at 02:42 PM. |
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 01:44 PM.







I support the
, when I found it and correct it I update the thread
Linear Mode
