[英]my UITableView's first item doesn't work
我的程序遇到一些奇怪的問題! 我創建了一個嵌套的可變數組,它由4個可變數組組成,每個可變數組包含一個字符串和另外4個數組,每個數組又包含兩個字符串。 這是我通過NSLog傳遞數組時收到的日志:
然后,我使用了3個tableview控制器以某種方式在這些數組中創建了導航,就像第一個tableview控制器一樣,我根據選擇了原始數組的哪個項來加載第二個tableview控制器,依此類推。
一切對所有數組都適用,除了第一個頂層(第一個包含
我使用objectAtIndex並具有tempProjectNumber,該屬性保存第一個用於選擇項目的tableview控制器的選定index.row。 但是,當我的第二個tableviewcontroller加載cell.textlabel.text時,我收到了sigbart錯誤:
由於未捕獲的異常'NSInvalidArgumentException'而終止應用程序,原因:'-[__ NSArrayI isEqualToString:]:無法識別的選擇器已發送到實例0x8987c80'
我設法找到了為cell.textlabel加載文本時嘗試訪問的項目的類,它說這是一個> __ NSCFConstantString。
這是完整的日志:
>2011-11-13 01:36:42.031 iCodeMobile[4763:15203] indexpath.row: 1 projectnumber:0
>2011-11-13 01:36:42.032 iCodeMobile[4763:15203] array: __NSCFConstantString
>2011-11-13 01:36:42.033 iCodeMobile[4763:15203] indexpath.row: 2 projectnumber:0
>2011-11-13 01:36:42.033 iCodeMobile[4763:15203] array: __NSCFConstantString
>2011-11-13 01:36:42.034 iCodeMobile[4763:15203] indexpath.row: 3 projectnumber:0
>2011-11-13 01:36:42.035 iCodeMobile[4763:15203] array: __NSCFConstantString
>2011-11-13 01:36:42.036 iCodeMobile[4763:15203] indexpath.row: 4 projectnumber:0
>2011-11-13 01:36:42.036 iCodeMobile[4763:15203] array: __NSArrayI>
index path.row記錄是第二個視圖控制器的表的行,項目號是第二個最高級別的數組,其中第一個項目是testproject1。 和數組日志記錄是我要訪問的項目的類。 如您所見,最后一個是NSArrayI,但我沒有使用類似的東西,正如您從前面的數組映射中可以看到的那樣。
有趣的是,如果我使用調試模式並進入每一行,則在所有單元格行都加載了正確的文本之后,我會收到此錯誤:
[CALayer objectAtIndex:]:無法識別的選擇器發送到實例0x7f51f40我不使用任何層,我什至不知道該怎么做!
請幫忙,因為我正在處理這個問題將近一個月。 我正在使用uipickerview,發生了相同的事情,相同的第一項問題和相同的SIGBART錯誤!
謝謝。
更新@Mundi:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (indexPath.row==0)
{
cell.textLabel.text = @"Please Select A folder";
}else
{
NSLog(@"indexpath.row: %u projectnumber:%u",indexPath.row,shared.tempProjectNumber);
id object = [[shared.fileNameContainer objectAtIndex:shared.tempProjectNumber] objectAtIndex:indexPath.row];
if ([object isKindOfClass:[NSString class]]){
NSLog(@"String: %@",[[[shared.fileNameContainer objectAtIndex:shared.tempProjectNumber] objectAtIndex:indexPath.row]objectAtIndex:0]);
}
else
{
NSLog(@"array: %@",[[[[shared.fileNameContainer objectAtIndex:shared.tempProjectNumber] objectAtIndex:indexPath.row]objectAtIndex:0]class]);
}
cell.textLabel.text = [[[shared.fileNameContainer objectAtIndex:shared.tempProjectNumber] objectAtIndex:indexPath.row]objectAtIndex:0];
};
return cell;
}
在這里,shared.tempProjectNumber是項目數組的記錄索引(我的主數組中最高級別的數組,即shared.fileNameContainer)。 這是我早些時候為該帖子獲得的記錄,並且在加載了表格的所有項目之后,我認為這是導致問題的最后一個項目,我收到sigbart錯誤! 非常感謝Mundi
更新:我找到了解決我的問題的簡便方法,因此沒有太多需要做的事情了,但感謝有人對此事有所了解
問候
您是否知道在c和(大多數其他編程語言)數組中索引從0
到count-1
? 因此,數組索引應該從0
到3
,而不是1
到4
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.