2013-05-07 60 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

相關問題