EXC_BAD_ACCESS генерируется в didSelectRowAtIndexPath - PullRequest
0 голосов
/ 05 декабря 2011

Пожалуйста, примите во внимание этот код:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    // Configure the cell.
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }


    NSDictionary *dict1 = [rows objectAtIndex:indexPath.row];
    NSLog(@"%@", dict1);
    if ([dict1 objectForKey:@"faqQues"] != [NSNull null]) {
        cell.textLabel.text = [dict1 objectForKey:@"faqQues"];

    } 



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    faqQuesID = [[rows objectAtIndex: indexPath.row] integerValue];    
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    //NSString *faqQuesID = [rows objectAtIndex:indexPath.row];    
    NSLog(@"faqQuesID ######### %@",faqQuesID);

    [prefs setInteger:faqQuesID forKey:@"faqQuesID"];
    [prefs setInteger:faqTypeID forKey:@"passFaqType"];

    helpDetailsViewController *hdVController = [[helpDetailsViewController alloc] initWithNibName:@"helpDetailsViewController" bundle:nil];     
    [self presentModalViewController:hdVController animated:YES];
    [hdVController release];
}


        cell.textLabel.textAlignment = UITextAlignmentLeft;
        cell.textLabel.font = [UIFont fontWithName:@"Arial" size:13.0];
        cell.textLabel.textColor = [UIColor blackColor];    
        cell.textLabel.highlightedTextColor = [UIColor blueColor];
        cell.textLabel.textAlignment = UITextAlignmentCenter;
        return cell;   

    }

// [prefs setInteger: 10 forKey: @ "faqQuesID"]; если я ставлю вручную целое число, то это работает, но когда я получаю значение формы indexPath.row, то это показывает ошибку // ошибка консоли

2011-12-05 18:16:30.312 test[3602:c203] -[__NSCFDictionary integerValue]: unrecognized selector sent to instance 0x719e400
2011-12-05 18:16:30.314 test[3602:c203] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary integerValue]: unrecognized selector sent to instance 0x719e400'

// я потратил больше пары часов, пожалуйста, дайте мне совет, как я могу решить эту проблему?

1 Ответ

2 голосов
/ 05 декабря 2011

В вашем cellForRowAtIndexPath:

NSDictionary *dict1 = [rows objectAtIndex:indexPath.row];

rows - это массив словарей.ОК.

В вашем didSelectRow:

faqQuesID = [[rows objectAtIndex: indexPath.row] integerValue];

, который мы можем разбить на:

NSDictionary *dict = [rows objectAtIndex:indexPath.row];
faQuesID = [dict integerValue];

NSDictionary не имеет integerValue метод - который точночто сообщение об ошибке говорит вам.Предположительно, вы хотите получить целое число из определенного объекта в словаре.

faqQuesID = [[[rows objectAtIndex: indexPath.row] objectForKey:@"faqQuesID"]integerValue];

Предположим, у вас есть NSNumber, хранящийся под ключом @"faqQuesID".

Итак, ваш didSelectRow метод должен выглядеть примерно так:

NSDictionary *faq = [rows objectAtIndex: indexPath.row];
[prefs setInteger:[[faq objectForKey:@"faqQuesID"] integerValue] forKey:@"faqQuesID"];     
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...