2014-05-08 14 views
1

在Xcode中,我創建了一個UITableViewDynamic Prototypes。第一個單元由buttonlabelMKMapView組成。無法在UITableViewCell中使用MKMapView發送SubviewToBack

在我...cellForRowAtIndexPath:方法我用下面的代碼:

UITableViewCell *header = [self getNewCell:@"entity_header"]; 

// Send map to back (put map behind everything else) 
MKMapView *MapView = (MKMapView*)[header viewWithTag:2]; 
[tableView sendSubviewToBack:MapView]; 
// Also tried using `header` here. [header sendSubviewToBack:MapView]; 

// Set the image of the back button. 
UIButton *backButton = (UIButton*)[header viewWithTag:1]; 
UIImage *backBtnImg = [UIImage imageNamed:@"images/backBtn.png"]; 
[backButton setImage:backBtnImg forState:UIControlStateNormal]; 
[tableView bringSubviewToFront:backButton]; 
// Also tried using `header` here. [header bringSubviewToFront:backButton]; 

我想給其他組件但是上面的代碼按預期不起作用背後的MKMapView

注意:我在此使用viewWithTag的原因是,我不必爲所有組件創建插座。 (這是很難從UITableViewCell內部創建網點而不使用更多的實現文件)

+1

[cell bringSubviewToFront:backButton];使用'cell'而不是'tableView'你的組件已經被添加到Cell而不是tableview .. – iphonic

+0

試過上面的建議,它沒有工作。 MKMapView仍然在所有其他組件之上。 –

回答

3

我想你使用的是自定義單元格。所以問題可能在這一行。 MKMapView *MapView = (MKMapView*)[header viewWithTag:2];請嘗試此操作。

MKMapView *MapView = (MKMapView*)[header.contentView viewWithTag:2]; 

而且他們這樣做。

[header.contentView sendSubviewToBack:MapView]; 

注:如果所有內容的子視圖具有範圍小於MKMapView手段,MKMapView總是會在屏幕上。

+0

非常感謝。這是答案。 =) –

+1

歡迎你。祝你好運 :) – Mani