我試圖在表格視圖中填充單元格(我有兩個自定義類型的單元格,其中包含使用標識符「info_cell」和「person_cell」創建的不同元素,在UITableView之上的分段控制上,我決定加載[tableView reload])。當我嘗試訪問單元格內的UILabels時,我得到的標籤爲空。UITableView中單元格內的UILabel始終爲空(兩個單元格原型)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = (viewType == INFO_VIEW) ? @"info_cell" :@"person_cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if(viewType == INFO_VIEW){
NSLog(@"INFO = %@", info_text_some_string);
UILabel *lblInfo = (UILabel *)[cell viewWithTag:200];
[lblInfo setText:info_text_some_string];
}
else{
// there is part for person
}
return cell;
}
相同的代碼工作時,我只有一個原型單元格內的表(UITableView是UIVewController內)。可以採取什麼問題就在這裏,我已經檢查100次:小區標識符都行,標籤標記爲200
這是UISegmentControl
- (IBAction)changeView:(id)sender {
UISegmentedControl *segmentedControl = (UISegmentedControl *) sender;
NSInteger selectedSegment = segmentedControl.selectedSegmentIndex;
if (selectedSegment == 0) {
viewType = INFO_VIEW;
}
else{
viewType = PERSON_VIEW;
}
[tableView reloadData];
}
我已經加入和必要的方法行動的tableView並連接代表我數據源。 有沒有人有任何想法爲什麼它爲空?
您可以發佈它爲你工作的解決方案,因爲我面臨類似的問題.. – Shivaay 2014-06-20 21:36:08