Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tableview and Searchbar

ValaronValaron Posts: 1New Users Noob
I would like to incorporate into my iPhone app menu (Table View) with a search. Can someone help me, how do I code in the below search insert a ??
I've already tried:

#import "FormelView.h"
@implementation FormelView
@synthesize schnittView, drehzahlView, tanaView, kegellaengeView,harteview,zeitspanvol,laengenview,volumenview,schwindungview,reibungview,leistungview,fehlkegelview,pyhagoview,bogenlview,fedlview,gewkview,vorview,schluweiview,trigo;
@synthesize mainTableView = ivMainTableView;
@synthesize filteredCandyArray;
@synthesize candySearchBar;

- (void)viewDidLoad {

[candySearchBar setShowsScopeBar:NO];
[candySearchBar sizeToFit];

// Hide the search bar until user scrolls up
CGRect newBounds = [[self mainTableView] bounds];
newBounds.origin.y = newBounds.origin.y + candySearchBar.bounds.size.height;
[[self mainTableView] setBounds:newBounds];

self.automaticallyAdjustsScrollViewInsets = NO;
self.navigationItem.title = NSLocalizedString(@more, nil);
arryweiterFunktionen = [[NSArray alloc] initWithObjects:
NSLocalizedString(@Schnittgeschwindigkeit, nil),
NSLocalizedString(@Drehzahl, nil),
NSLocalizedString(@tan, nil),
NSLocalizedString(@Kegellänge, nil),
NSLocalizedString(@Harte, nil),
NSLocalizedString(@ZeitSpan, nil),
...
NSLocalizedString(@Schluweit, nil),
NSLocalizedString(@Trigo, nil),nil];
filteredCandyArray = [NSMutableArray arrayWithCapacity:[arryweiterFunktionen count]];

// Reload the table
[[self mainTableView] reloadData];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{
return [filteredCandyArray count];
}
else
{
return [arryweiterFunktionen count];
}
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @Cell;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//cell.textLabel.text = [arryweiterFunktionen objectAtIndex:indexPath.row];

if (tableView == self.searchDisplayController.searchResultsTableView)
{
[filteredCandyArray objectAtIndex:[indexPath row]];
}
else
{
[arryweiterFunktionen objectAtIndex:[indexPath row]];
}
cell.textLabel.text = [arryweiterFunktionen objectAtIndex:indexPath.row];
// Configure the cell

return cell;

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// if(indexPath.section == 0)
// switch (indexPath.row) {
switch (indexPath.row) {
case 0:
if(self.schnittView == nil) {
SchnittView *viewTwo = SchnittView alloc] initWithNibName:@"SchnittView" bundle:[NSBundle mainBundle;
self.schnittView = viewTwo;
}
[self.navigationController pushViewController: self.schnittView animated:YES];
break;
case 1:
if(self.drehzahlView == nil) {
DrehzahlView *viewTwo = DrehzahlView alloc] initWithNibName:@"DrehzahlView" bundle:[NSBundle mainBundle;
self.drehzahlView = viewTwo;
}
[self.navigationController pushViewController:self.drehzahlView animated:YES];
break;
case 2:
if(self.tanaView == nil) {
tana2View *viewTwo = tana2View alloc] initWithNibName:@"tana2View" bundle:[NSBundle mainBundle;
self.tanaView = viewTwo;
}
[self.navigationController pushViewController:self.tanaView animated:YES];
break;
...
...
case 18:
if(self.trigo == nil) {
TrigView *viewTwo = TrigView alloc] initWithNibName:@"TrigView" bundle:[NSBundle mainBundle;
self.trigo = viewTwo;
}
[self.navigationController pushViewController:self.trigo animated:YES];
break;
default:
break;
}
}

#pragma mark - Segue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ( [[segue identifier] isEqualToString:@candyDetail] ) {
UIViewController *candyDetailViewController = [segue destinationViewController];

// In order to manipulate the destination view controller, another check on which table (search or normal) is displayed is needed
if(sender == self.searchDisplayController.searchResultsTableView) {
NSIndexPath *indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
NSString *destinationTitle = filteredCandyArray objectAtIndex:[indexPath row name];
[candyDetailViewController setTitle:destinationTitle];
}
else {
NSIndexPath *indexPath = [self.mainTableView indexPathForSelectedRow];
NSString *destinationTitle = arryweiterFunktionen objectAtIndex:[indexPath row name];
[candyDetailViewController setTitle:destinationTitle];
}

}
}

#pragma mark Content Filtering

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
// Update the filtered array based on the search text and scope.

// Remove all objects from the filtered search array
[self.filteredCandyArray removeAllObjects];

// Filter the array using NSPredicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@SELF.name contains[c] %@",searchText];
NSArray *tempArray = [arryweiterFunktionen filteredArrayUsingPredicate:predicate];

if(![scope isEqualToString:@All]) {
// Further filter the array with the scope
NSPredicate *scopePredicate = [NSPredicate predicateWithFormat:@SELF.category contains[c] %@",scope];
tempArray = [tempArray filteredArrayUsingPredicate:scopePredicate];
}

filteredCandyArray = [NSMutableArray arrayWithArray:tempArray];
}

#pragma mark - UISearchDisplayController Delegate Methods

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString scope:
self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex];
return YES;
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:
self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption;
return YES;
}

#pragma mark - Search Button

- (IBAction)goToSearch:(id)sender
{
[candySearchBar becomeFirstResponder];
}

@end

Deleted to save space have some lines (viewDidUnload, etc.).

update:
i have add jet a searchbar. i have edit the .m file above
this is the.h file:

#import <UIKit/UIKit.h>
#import ...
@interface FormelView : UIViewController <UISearchBarDelegate, UISearchDisplayDelegate>
{
UITableView *ivMainTableView;
NSArray *arryweiterFunktionen;
ZeitSpanVol* zeitspanvol;
...
VolumenView* volumenview;

}
@property (strong,nonatomic) NSMutableArray *filteredCandyArray;
@property IBOutlet UISearchBar *candySearchBar;

@property (nonatomic, strong)ZeitSpanVol* zeitspanvol;
...
@property(nonatomic, strong)TrigView* trigo;
@property (nonatomic, strong) IBOutlet UITableView *mainTableView;

@end

many greetings Markus
Sign In or Register to comment.