__NSArrayI rangeOfCharacterFromSet
__NSArrayI rangeOfCharacterFromSet
我有以下 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'
由于逗号分隔符,您的应用程序在索引 5 上崩溃。索引 5 有一个数组,它不仅包含一个对象,而且包含三个对象。
(
"Diphtheria,
pertussis,
and tetanus DTaP"
)
这样你只取了0个索引,剩下的没有取。
将此对象中的逗号 (,) 分隔符替换为 (.) 分隔符,它工作正常。
您的数组 vaccScheduleArray_(不寻常的名称,您应该认真采用通用命名约定)不是六个字符串的数组。它是一个由六个数组组成的数组,每个数组包含一个字符串。所以你试图将标签的文本设置为 NSArray。
这是未来案例的赠品:崩溃显然是因为 NSString 方法被发送到 NSArray 对象。因此,在某些时候,您将 NSArray 提供给需要 NSString 的人。然后问题是"where"?
NSArray *vaccineNameArray = [vaccScheduleArray_ objectAtIndex:indexPath.row];
cell.vaccNameLabel.text = vaccineNameArray[0];
问题是,您正在将数组分配给 label's
、text
属性。
我有以下 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'
由于逗号分隔符,您的应用程序在索引 5 上崩溃。索引 5 有一个数组,它不仅包含一个对象,而且包含三个对象。
(
"Diphtheria,
pertussis,
and tetanus DTaP"
)
这样你只取了0个索引,剩下的没有取。
将此对象中的逗号 (,) 分隔符替换为 (.) 分隔符,它工作正常。
您的数组 vaccScheduleArray_(不寻常的名称,您应该认真采用通用命名约定)不是六个字符串的数组。它是一个由六个数组组成的数组,每个数组包含一个字符串。所以你试图将标签的文本设置为 NSArray。
这是未来案例的赠品:崩溃显然是因为 NSString 方法被发送到 NSArray 对象。因此,在某些时候,您将 NSArray 提供给需要 NSString 的人。然后问题是"where"?
NSArray *vaccineNameArray = [vaccScheduleArray_ objectAtIndex:indexPath.row];
cell.vaccNameLabel.text = vaccineNameArray[0];
问题是,您正在将数组分配给 label's
、text
属性。