我知道這裏有很多類似的問題,但我回顧了一堆,我仍然堅持。有人可以查看我的代碼,看看他們是否可以找到UITableView方法未被調用的原因。我檢查了數組並且它正在被填充,但是當我在表上調用reloadData時,什麼都沒有。UITableView無法重新加載數據後傳遞
該過程是我正在進行SOAP調用以獲取數據,將返回的XML解析爲字典(每個條目都是存儲信息的數組),然後將其傳遞給表的視圖控制器。然後我遍歷字典,獲取每個數組,獲取商店名稱並將其放置在dataPointTitles數組中。這是我桌子的數據源。代表已設置。當應用程序進入時,由於尚未裝入數據,因此數據源上的計數爲0,因此是正確的。一旦用戶檢索數據,dataPointTitles數組將被填充(請參閱下面的控制檯日誌打印輸出),但沒有任何方法被觸發。
這裏是我的代碼:
h文件:.m文件的
@interface DataController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
NSMutableDictionary* dataDict;
NSMutableArray* dataPointTitles;
UILabel* lblDataLabel;
UITableView* tblDataTable;
SoapController* soapManager;
ColorController* colorManager;
MKMapView* thisMap;
CLPlacemark* thisPlaceMark;
}
@property (nonatomic, retain) NSMutableDictionary* dataDict;
- (void) parseData;
- (void) setDataDict : (NSMutableDictionary*) passedDict;
@end
相關部分
#import "DataController.h"
@interface DataController()
@end
@implementation DataController
@synthesize dataDict;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//color manager
colorManager = [ColorController new];
//add data label
lblDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 40.0, 300.0, 30.0)];
[lblDataLabel setTextColor:[UIColor whiteColor]];
[lblDataLabel setFont: [UIFont fontWithName:@"Helvetica-Bold" size: 12]];
[lblDataLabel setText:@"Local Medicare Providers and Services:"];
[lblDataLabel setBackgroundColor:[UIColor clearColor]];
//add the table
tblDataTable = [[UITableView alloc] initWithFrame: CGRectMake(10.0, 70.0, 300.0, 300.0)];
tblDataTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tblDataTable.separatorColor = [colorManager setColor:176.0:196.0:222.0];
tblDataTable.layer.borderWidth = 1.0;
tblDataTable.rowHeight = 20.0;
tblDataTable.scrollEnabled = YES;
tblDataTable.delegate = self;
tblDataTable.dataSource = self;
[self.view addSubview:lblDataLabel];
[self.view addSubview:tblDataTable];
}
- (void) setDataDict : (NSMutableDictionary*) passedDict {
dataDict = passedDict;
[self parseData];
}
#pragma mark Parsing Data
- (void) parseData {
dataPointTitles = [[NSMutableArray alloc] init];
for(NSString* thisObj in dataDict) {
NSArray* thisDataSet = [dataDict objectForKey:thisObj];
[dataPointTitles addObject:[thisDataSet objectAtIndex:1]];
}
NSLog(@"%@", dataPointTitles);
[tblDataTable reloadData];
}
#pragma mark Table Management
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"%i", [dataPointTitles count]);
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [dataPointTitles count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"tableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.textColor = [UIColor colorWithRed:66.0/255.0 green:66.0/255.0 blue:66.0/255.0 alpha:1];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size: 13.0];
cell.textLabel.text = [dataPointTitles objectAtIndex:indexPath.row];
CGRect cellFrame = [cell frame];
cellFrame.size.height = 50.0;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString* thisDataPointTitle = [dataPointTitles objectAtIndex:indexPath.row];
for(NSString* thisObj in dataDict) {
NSArray* thisDataPoint = [dataDict objectForKey:thisObj];
if ([thisDataPoint objectAtIndex:1] == thisDataPointTitle) {
}
}
}
下面是來自parseData方法輸出的console.log:
"PASSAVANT DEVELOPMENT CORPORATION",
"MYERS DRUG STORE INC",
"WAL-MART STORES EAST LP",
"JAMES GRANT MCGINNESS",
"WAL-MART STORES EAST INC",
"WILLIAM J DIMINO",
"SUBURBAN EYE CARE OPTOMETRIC",
"CMMC INC",
"FOR EYES OPTICAL CO INC",
"LACONS PHARMACY INC",
"PASSAVANT DEVELOPMENT CORPORATION",
"WAL-MART STORES EAST LP",
"RITE AID CORPORATION",
"JAMES GRANT MCGINNESS",
"ABLE MEDICAL EQUIPMENT",
"GIANT FOOD STORES LLC",
"WALGREEN CO",
"ACCESS CARE INC",
"RITE AID CORPORATION",
"CVS DEKALB NORRISTOWN INC",
"FS-PHILADELPHIA LLC",
"DRUG EMPORIUM INC",
"PAUL D HALPERN OD",
"HARRY W FIRTH JR",
"ABLE MEDICAL EQUIPMENT",
"ACME MARKETS INC DE",
"BROWN'S CH LLC",
"THE MEDICINE SHOPPE",
"MYERS DRUG STORE INC",
"NCS HEALTHCARE OF PENNSYVANIA INC",
"ACCESS CARE INC",
"NORMATEC INC",
"WAL-MART STORES EAST LP",
"COLE VISION CORPORATION",
"RESTORATIVE INNOVATIONS INC",
"ABLE MEDICAL EQUIPMENT",
"CMMC INC",
"KMART OF PENNSYLVANIA LP",
"WAL-MART STORES EAST LP",
"THERESE C DESCHENES OD PC",
"ALLEN SOFFER OD PC",
"WAL-MART STORES EAST INC",
"RITE AID CORPORATION",
"NORRISTOWN CVS INC",
"WAL-MART STORES EAST LP",
"FOR EYES OPTICAL CO INC",
"LACONS PHARMACY INC"
在'parseData'中,你還可以記錄'tblDataTable'和'tblDataTable.dataSource'的值嗎? –
我得到每個空...我可以看到數據源爲空,但爲什麼表? – PruitIgoe
「viewDidLoad」之前調用了任何機會'parseData'(或者你有兩個不同的'DataController'對象)?否則,我會試圖讓'tblDataTable'成爲一個強大的屬性,強制所有更新都通過'setter',並嘗試追蹤它被更改的位置。 –