2016-08-06 5 views
0

UITableView zuerst die Daten perfekt geladen hat. Wenn ich NSPredicate auf NSMutableDictionary * Liste und Tabelle neu laden die Daten anwendet, nach dem Scrollen die App stürzt ab. Ich denke, ein großes Problem ist in numberOfRowsInSection. Hier ist mein CodeApp stürzt nach dem erneuten Laden von Tabellenansichtsdaten ab, nachdem NSPredicate

ViewDidLoad

NSArray *allstartingPrice = @[@100,@200,@400,@500,@300,@100,@1000,@1000,@200,@700]; 
NSArray *alldistanceFrom = @[@7,@9,@8,@3,@30,@35,@50,@10,@15,@25]; 

NSAray *startingPrice = allstartingPrice; 
NSAray *distanceFrom = alldistanceFrom; 

list = [[NSMutableDictionary alloc] init]; 
[list setObject:startingPrice forKey:@"startingfrom"]; 
[list setObject:distanceFrom forKey:@"distance"]; 

und hier ist Verfahren zum Filtern von Daten.

Daten filtern perfekt, aber wenn uitableviewscroll und erreicht am Ende der Tabelle App abstürzt. andere Methoden

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;{ 

    return 150; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    FSParallaxTableViewCell *cell = (FSParallaxTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
    cell.cellImageView.image = [UIImage imageNamed:[[list objectForKey:@"imagesnames"] objectAtIndex:indexPath.row]]; 
    cell.cellImageView.contentMode = UIViewContentModeScaleAspectFill; 

    cell.backgroundColor = [UIColor clearColor]; 

    UIImage *img = [UIImage imageNamed:@"flat_color.png"]; 
    cell.startingat.backgroundColor = [UIColor colorWithPatternImage:img]; 
    cell.startingat.font = [UIFont fontWithName:@"HelveticaNeue-light" size:12]; 
    cell.startingat.textColor = [UIColor blackColor]; 
    cell.startingat.adjustsFontSizeToFitWidth = YES; 
    UIImage *img2 = [UIImage imageNamed:@"flat_color.png"]; 
    cell.distance.backgroundColor = [UIColor colorWithPatternImage:img2]; 
    cell.distance.textAlignment = NSTextAlignmentCenter; 
    cell.distance.font = [UIFont fontWithName:@"HelveticaNeue-light" size:9]; 
    cell.distance.textColor = [UIColor whiteColor]; 
    cell.distance.adjustsFontSizeToFitWidth = YES; 
    NSString *dis = [[NSString alloc] initWithFormat:@"%@ km", [[list objectForKey:@"distance"] objectAtIndex:indexPath.row]]; 
    return cell; 
} 

Fehlerprotokoll

enter image description here

+0

Zeigen Sie auch die TableView-Methoden an. –

+0

ist die Anzahl der Zeilen im Abschnitt gleich countr des Arrays, das den Wert enthält? –

+0

Fügen Sie die Methode tableviewDatasource hinzu, damit Ihr Problem verstanden wird. –

Antwort

0

Das Problem Sie konfrontiert sind, ist, weil Sie zwei unterschiedliche Array haben, und beide haben unterschiedliche Filter auf es, das Problem verursacht, versuchen Sie ein einzelnes Array zu verwenden, das ein solches Dictionary-Objekt enthält. Ändere deinen Code so.

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    NSArray *allstartingPrice = @[@100,@200,@400,@500,@300,@100,@1000,@1000,@200,@700]; 
    NSArray *alldistanceFrom = @[@7,@9,@8,@3,@30,@35,@50,@10,@15,@25]; 

    array = [[NSMutableArray alloc] init]; 
    for (NSInteger i=0; i<allstartingPrice.count; i++) { 
     NSMutableDictionary *dic = [[NSMutableDictionary alloc] init]; 
     [dic setValue:[allstartingPrice objectAtIndex:i] forKey:@"startingfrom"]; 
     [dic setValue:[alldistanceFrom objectAtIndex:i] forKey:@"distance"]; 
    } 
} 

- (void) sortTable{ 
    //int match = numberOfBudget; 
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startingfrom <= %d && distance <= %d", 100, 10]; 
    filteredArray = [NSMutableArray arrayWithArray:[array filteredArrayUsingPredicate:predicate]]; 
    [self.tableView reloadData]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if (filteredArray.count > 0) { 
     return filteredArray.count; 
    } 
    return array.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSDictionary *dic; 
    if (filteredArray.count > 0) { 
     dic = [filteredArray objectAtIndex:indexPath.row]; 
    } 
    else { 
     dic = [array objectAtIndex:indexPath.row]; 
    } 
    FSParallaxTableViewCell *cell = (FSParallaxTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
    cell.cellImageView.image = [UIImage imageNamed:[[list objectForKey:@"imagesnames"] objectAtIndex:indexPath.row]]; 
    cell.cellImageView.contentMode = UIViewContentModeScaleAspectFill; 

    cell.backgroundColor = [UIColor clearColor]; 

    UIImage *img = [UIImage imageNamed:@"flat_color.png"]; 
    cell.startingat.backgroundColor = [UIColor colorWithPatternImage:img]; 
    cell.startingat.font = [UIFont fontWithName:@"HelveticaNeue-light" size:12]; 
    cell.startingat.textColor = [UIColor blackColor]; 
    cell.startingat.adjustsFontSizeToFitWidth = YES; 
    cell.startingat.text = [dic valueForKey:@"startingfrom"]; 
    UIImage *img2 = [UIImage imageNamed:@"flat_color.png"]; 
    cell.distance.backgroundColor = [UIColor colorWithPatternImage:img2]; 
    cell.distance.textAlignment = NSTextAlignmentCenter; 
    cell.distance.font = [UIFont fontWithName:@"HelveticaNeue-light" size:9]; 
    cell.distance.textColor = [UIColor whiteColor]; 
    cell.distance.adjustsFontSizeToFitWidth = YES; 
    cell.distance.text = [dic valueForKey:@"distance"]; 
    return cell; 
} 
Verwandte Themen