2012-04-19 17 views
0

我有一個相當複雜的UITableViewCell,並在生產代碼我能拉出一個選擇的UILabel與以下如何多個項目添加到一個UITableViewCell的內容查看

[[[[[[cell subviews] objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:4]; 

一切正常沒問題 - 我遇到的問題是當我嘗試創建一個簡單的單元測試,以顯示預期如何工作。

出於某種原因,我不能夠建立具有在細胞中的內容查看屬性2項的情景

這樣我就可以輕鬆搞定[電池子視圖] objectAtIndex:0],但從來沒有1

在我的測試幫助我做下面來模擬這個(沒有運氣)

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; 
UIView *view1 = [[UIView alloc] init]; 
UILabel *label1 = [[UILabel alloc] init]; 
UIView *view2 = [[UIView alloc] init]; 
UILabel *label2 = [[UILabel alloc] init]; 

[view1 addSubview:label1]; 
[cell.contentView addSubview:view1]; 

[view2 addSubview:label1]; 
[view2 addSubview:label2]; 
[cell.contentView addSubview:view2]; 

NSLog(@"inside ...%@", [[cell subviews] objectAtIndex:1]); 

回答

0

不能添加LABEL1的VIEW1和視圖2,你必須創建兩個不同的標籤。一個視圖只能有一個超視圖,所以當你說[view2 addSubview:label1];時,label1會從視圖1中移除。

相關問題