在Xcode中,我創建了一個UITableView
和Dynamic Prototypes
。第一個單元由button
,label
和MKMapView
組成。無法在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
內部創建網點而不使用更多的實現文件)
[cell bringSubviewToFront:backButton];使用'cell'而不是'tableView'你的組件已經被添加到Cell而不是tableview .. – iphonic
試過上面的建議,它沒有工作。 MKMapView仍然在所有其他組件之上。 –