2013-05-07 113 views
0

这有可能返回如在部分行中的(而不是计数)的数量一个NSMutableArraynumberofRowsinSection是否可以返回NSMutableArray的VALUES?

- (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]; 
} 

的应用只是崩溃,并且当我把恒定值(返回2例如),应用程序运行,但它没有给出预期的结果。 我肯定错过了一些东西。 谢谢你的帮助。

回答

5

看来你正在返回一个NSNumber,而该方法期待一个NSInteger。你应该如下转换NSNumber。

- (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] intValue]; 
} 
+0

您如何检测的问题:d!它解决了我的问题:)。非常感谢你,并接受。 – androniennn 2013-05-07 20:22:06

+1

不客气,考虑到NSArray只能容纳NSNumbers! :) – Matt 2013-05-07 20:30:33

1

不。您正在返回一个NSInteger。如果您选择,您需要显式声明一个属性来保存该值。

1

如果阵列持有的NSNumber的情况下,你需要将对象转换为NSInteger的:

return [[arrayofNombre objectAtIndex:section] integerValue]; 
+0

非常感谢,你是最好的。问题解决了 :)。 – androniennn 2013-05-07 20:22:41

相关问题