2013-04-10 29 views
0

我用下面的代碼來調用UITableView單元測試的UITableView

-(void)testJumpSection 

{ 
    NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:0 inSection:0]; 
    [viewControllerObject tableView:viewControllerObject.masterTableView didSelectRowAtIndexPath:indexPath1]; 
    int backButtonSection = viewControllerObject.backButtonSection; 
    NSIndexPath *indexPath2= [NSIndexPath indexPathForRow:0 inSection:2]; 
    [viewControllerObject tableView:viewControllerObject.masterTableView didSelectRowAtIndexPath:indexPath2]; 
    int backButtonSection2 = viewControllerObject.backButtonSection; 
    [viewControllerObject backButtonView:viewControllerObject.button1]; 
    int backButtonSectionTestValue = viewControllerObject.backButtonSection; 
    STAssertTrue(backButtonSectionTestValue==1, @"TestJumpSection"); 
} 

我寫這篇測試案例展開/摺疊uitableview.When用戶在部分0點擊行,然後點擊節3.現在用戶可以點擊後退按鈕導航第2節。現在我必須得到結果backButtonsection值減1。

它工作正常,但我無法獲得選定的部分值,並且我得到這個錯誤:

[__NSCFConstantString stringByAppendingString:]: nil argument"

有關我在做什麼錯的任何想法?

+0

你從哪裏得到錯誤?你可以告訴我們你的'-tableView:didSelectRowAtIndexPath:'的實現嗎? – 2013-04-10 06:17:46

+0

發佈一些更多的代碼。 – 2013-04-10 06:18:42

+0

你有什麼問題可以理解錯誤信息嗎? – 2013-04-10 08:56:32

回答

0

很明顯,您致電stringByAppendingString:__NSCFConstantString的參數爲nil

一個簡單的例子,將導致此問題是

[@"some string" stringByAppendingString:nil]; 

更可能的原因將是

NSString *str; 
str = @"some string" 
NSString *anotherStr = nil; 
// some other code that should set anotherStr but did not 
NSString *result = [str stringByAppendingString:anotherStr]; // error 

所以去尋找stringByAppendingString:,並檢查他們的說法

順便說一句,你應該無論如何,從調試器知道這一點,因爲它應該告訴你哪條線路導致問題。