能不能将NSMutableArray返回成数字形式。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"number of rows in section: %@",[arrayofNombre objectAtIndex:section]);//it prints the right value
return [arrayofNombre objectAtIndex:section];
}
代码一运行就崩溃。如果放进一个常数值,运行之后的结果也不对。求高手指点,谢谢。
首先保证你的section 不会超过下标索引,不然会因超出索引而引发程序crash
如果要返回NSInteger需要作类型转换
return [[arrayofNombre objectAtIndex:section] intValue];
但要保证你数组中的都是int类型,不然也会因为类型转换失败而导致程序crash.
如果数组中有NSNumber
的实例,需要转换对象到NSInteger
。
return [[arrayofNombre objectAtIndex:section] integerValue];