성공적으로 UISearchcontroller 내 UITableview 구현하려면 노력하고 있지만 다음 문제가 있어요, 다음보기 컨트롤러를 indexPath.row 메서드를 사용하여 데이터를 전달하고 검색 할 때 indexPath.row 변경 두 번째로 여러 배열을 사용하고 있습니다. 내 tableview에 내 데이터에 대한, 그리고 내가 한 일은 다른 모든 배열 내용을 보유하고 그것을 통해 검색하는 다른 배열을 만들고, 그것은 indexPath 때문에 내 데이터를 전달하려는 경우를 제외하고는 모두 완벽하게 작동합니다. 행을 변경하는 대신 셀을 유지하는 것입니다. 제 코드를 확인하고 도움을받을 수 있는지 확인하십시오.검색 문제를 사용할 때 IndexPath.row가 변경됩니까?
#import "AbsViewController.h"
@interface AbsViewController()
@end
@implementation AbsViewController {
//these are all my arrays
//The arrays that carry for no equipment.
NSArray *tableData;
NSArray *thumbnails;
NSArray *sets;
NSArray *reps;
NSArray *instructions;
NSArray *materials;
NSArray *status;
NSArray *tips;
NSArray *difficulty;
NSArray *target;
//The arrays that carry for equipment.
NSArray *tableData1;
NSArray *thumbnails1;
NSArray *sets1;
NSArray *reps1;
NSArray *instructions1;
NSArray *materials1;
NSArray *status1;
NSArray *tips1;
NSArray *difficulty1;
NSArray *target1;
//The arrays that carry for bosu ball.
NSArray *tableData2;
NSArray *thumbnails2;
NSArray *sets2;
NSArray *reps2;
NSArray *instructions2;
NSArray *materials2;
NSArray *status2;
NSArray *tips2;
NSArray *difficulty2;
NSArray *target2;
//The arrays that carry for physio ball.
NSArray *tableData3;
NSArray *thumbnails3;
NSArray *sets3;
NSArray *reps3;
NSArray *instructions3;
NSArray *materials3;
NSArray *status3;
NSArray *tips3;
NSArray *difficulty3;
NSArray *target3;
//The arrays that carry for weighted.
NSArray *tableData4;
NSArray *thumbnails4;
NSArray *sets4;
NSArray *reps4;
NSArray *instructions4;
NSArray *materials4;
NSArray *status4;
NSArray *tips4;
NSArray *difficulty4;
NSArray *target4;
//Search array
NSArray *tableData5;
NSArray *status5;
NSArray *thumbnails5;
//The array for the search results.
NSArray *searchResults;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Abdominal";
//Here im initializing my arrays.
// Find out the path of my array.
NSString *path = [[NSBundle mainBundle] pathForResource:@"Abs" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
tableData = [dict objectForKey:@"name"];
thumbnails = [dict objectForKey:@"imageFile"];
status = [dict objectForKey:@"status"];
// Find out the path of recipes.plist
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"Abs1" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict1 = [[NSDictionary alloc] initWithContentsOfFile:path1];
tableData1 = [dict1 objectForKey:@"name"];
thumbnails1 = [dict1 objectForKey:@"imageFile"];
status1 = [dict1 objectForKey:@"status"];
// Find out the path of recipes.plist
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"Abs2" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict2 = [[NSDictionary alloc] initWithContentsOfFile:path2];
tableData2 = [dict2 objectForKey:@"name"];
thumbnails2 = [dict2 objectForKey:@"imageFile"];
status2 = [dict2 objectForKey:@"status"];
// Find out the path of recipes.plist
NSString *path3 = [[NSBundle mainBundle] pathForResource:@"Abs3" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict3 = [[NSDictionary alloc] initWithContentsOfFile:path3];
tableData3 = [dict3 objectForKey:@"name"];
thumbnails3 = [dict3 objectForKey:@"imageFile"];
status3 = [dict3 objectForKey:@"status"];
NSString *path4 = [[NSBundle mainBundle] pathForResource:@"Abs4" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict4 = [[NSDictionary alloc] initWithContentsOfFile:path4];
tableData4 = [dict4 objectForKey:@"name"];
thumbnails4 = [dict4 objectForKey:@"imageFile"];
status4 = [dict4 objectForKey:@"status"];
//this is the array that carries all the content.
NSString *path5 = [[NSBundle mainBundle] pathForResource:@"AbsTotal" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict5 = [[NSDictionary alloc] initWithContentsOfFile:path5];
tableData5 = [dict5 objectForKey:@"name"];
status5 = [dict5 objectForKey:@"status"];
thumbnails5 = [dict5 objectForKey:@"thumbnails"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (self.searchDisplayController.isActive) {
return 1;
}
return 5 ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [searchResults count];
}
else if (section == 0) {
return [tableData count];
}
else if (section == 1) {
return [tableData1 count];
}
else if (section == 2) {
return [tableData2 count];
}
else if (section == 3) {
return [tableData3 count];
}
else if (section == 4) {
return [tableData4 count];
}
else {
return [tableData5 count];
}
}
//this is my cellForRowAtIndexPath method.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"ExerciseCell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
cell.textLabel.text = [searchResults objectAtIndex:indexPath.row];
}
else if (indexPath.section == 0) {
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Type: %@", [status objectAtIndex:indexPath.row]];
cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
}
else if (indexPath.section == 1) {
cell.textLabel.text = [tableData1 objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Type: %@", [status1 objectAtIndex:indexPath.row]];
cell.imageView.image = [UIImage imageNamed:[thumbnails1 objectAtIndex:indexPath.row]];
}
else if (indexPath.section == 2) {
cell.textLabel.text = [tableData2 objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Type: %@", [status2 objectAtIndex:indexPath.row]];
cell.imageView.image = [UIImage imageNamed:[thumbnails2 objectAtIndex:indexPath.row]];
}
else if (indexPath.section == 3) {
cell.textLabel.text = [tableData3 objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Type: %@", [status3 objectAtIndex:indexPath.row]];
cell.imageView.image = [UIImage imageNamed:[thumbnails3 objectAtIndex:indexPath.row]];
}
else if (indexPath.section == 4) {
cell.textLabel.text = [tableData4 objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Type: %@", [status4 objectAtIndex:indexPath.row]];
cell.imageView.image = [UIImage imageNamed:[thumbnails4 objectAtIndex:indexPath.row]];
}
else {
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Type: %@", [status objectAtIndex:indexPath.row]];
cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
}
return cell;
}
//this is where i've attempted to fix the issue but didn't work.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger rowNumber = 0;
for (NSInteger i = 0; i < indexPath.section; i++) {
rowNumber += [self tableView:tableView numberOfRowsInSection:i];
}
rowNumber += indexPath.row;
NSLog(@"%ld",(long)rowNumber);
}
//this is where i filter my tableview
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@", searchText];
searchResults = [tableData5 filteredArrayUsingPredicate:resultPredicate];
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
//Here i create my view for my header/
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,25)];
customView.backgroundColor = [UIColor belizeHoleColor];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.backgroundColor = [UIColor belizeHoleColor];
headerLabel.font = [UIFont fontWithName:@"Avenir-Black" size:14];
headerLabel.frame = CGRectMake(6,0,320,25);
if (section == 1) {
headerLabel.text = @"";
}
if (section == 2) {
headerLabel.text = @"";
}
if (section == 3) {
headerLabel.text = @"";
}
if (section == 4) {
headerLabel.text = @"";
}
if (section == 0) {
headerLabel.text = @"";
}
headerLabel.textColor = [UIColor cloudsColor];
[customView addSubview:headerLabel];
return customView;
}
누군가 도움을 주시면 감사하겠습니다. 사전에 감사합니다. u는 검색 결과 테이블에 도청
U 말은, indexpath는 –
이 @Shan 네 그게 전부는 groupedtableview 다른 – user2600115
변화가 일어나는 것은 유 searchdisplaycontroller의의 tableview에 도청 있기 때문이다 뭐죠 –