0

我知道这里有很多类似的问题,但我复习了一堆,但仍然卡住了。有人可以查看我的代码,看看他们是否能找到未调用 UITableView 方法的原因。我检查了数组,它正在被填充,但是当我在表上调用 reloadData 时,什么也没有。

这个过程是我进行 SOAP 调用以获取数据,将返回的 XML 解析为字典(每个条目都是存储信息的数组),然后将其传递给表的视图控制器。然后我遍历字典,获取每个数组,获取商店名称并将其放在 dataPointTitles 数组中。那是我表的数据源。代表已定。当应用程序启动时,我在数据源上的计数为 0,这是正确的,因为尚未加载任何数据。一旦用户检索到数据,dataPointTitles 数组就会被填充(请参阅下面的控制台日志打印输出),但不会触发任何方法。

这是我的代码:

.h 文件:

@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

.m 文件的相关部分

#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"
4

1 回答 1

1

从评论中:显然我们遇到了一个问题,即逻辑中涉及多个DataController对象并在解析/视图加载中引起一些混乱。

于 2012-06-29T15:31:55.383 回答