__NSArrayI rangeOfCharacterFromSet

时间:2015-03-11 07:13:45

标签: ios objective-c uitableview nsmutablearray

我有以下NSMutableArray。

 NSLog(@"vacc_name:%@",vaccScheduleArray_);

输出是:

vacc_name:(
        (
        "Hepatitis B (HepB)"
    ),
        (
        "Hepatitis B (HepB)  2nd"
    ),
        (
        "Hepatitis B (HepB)  2nd"
    ),
        (
        "Rotavirus 1st"
    ),
        (
        "Rotavirus 2nd"
    ),
        (
        "Diphtheria, pertussis,and tetanus DTaP"
    )

我的uitableview代码是:

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    scheduleTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"MyScheduleCell"];
    if (!cell)
    {
        [tableView registerNib:[UINib nibWithNibName:@"scheduleTableViewCell" bundle:nil] forCellReuseIdentifier:@"MyScheduleCell"];
        cell = [tableView dequeueReusableCellWithIdentifier:@"MyScheduleCell"];
    }

    cell.vaccNameLabel.text=[vaccScheduleArray_ objectAtIndex:indexPath.row];
    NSLog(@"vaccine name:%@",cell.vaccNameLabel.text);

    return cell;
}

我收到了这个错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x175f3230'

3 个答案:

答案 0 :(得分:0)

您的阵列vaccScheduleArray_(不寻常的名称,您应该认真采用通用的命名约定)不是六个字符串的数组。它是一个包含六个数组的数组,每个数组包含一个字符串。所以你试图将标签的文本设置为NSArray。

以下是未来案例的赠品:崩溃显然是因为NSString方法被发送到NSArray对象。因此,在某些时候,您正在向需要NSString的人提供NSArray。然后问题是“在哪里”?

答案 1 :(得分:0)

NSArray *vaccineNameArray = [vaccScheduleArray_ objectAtIndex:indexPath.row];
cell.vaccNameLabel.text = vaccineNameArray[0];

问题是,您要将数组分配给label'stext属性。

答案 2 :(得分:-1)

由于逗号分隔符,您的应用程序因索引5而崩溃。索引5有一个数组,它不仅包含一个对象,还包含三个对象。

(
    "Diphtheria, 
     pertussis,
     and tetanus DTaP"
)

这样你只剩下0个索引。

将逗号(,)分隔符替换为此对象中的(。)分隔符,它可以正常工作。