我知道这里有很多类似的问题,但我回顾了一堆,但仍然卡住了。有人可以查看我的代码,看看他们是否可以找到没有调用UITableView方法的原因。我检查了数组并且它正在填充但是当我在表上调用reloadData时,什么都没有。
过程是我正在进行SOAP调用以获取数据,将返回的XML解析为字典(每个条目是一个存储信息数组),然后将其传递给表的视图控制器。然后我遍历字典,获取每个数组,获取商店名称并将其放在dataPointTitles数组中。那是我桌子的数据源。代表们已经确定。当app inits我在数据源上得到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
<。p。文件的相关部分
#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"
答案 0 :(得分:1)
从评论中看来:显然我们遇到了一个问题,即逻辑中涉及多个DataController
对象,导致解析/视图加载时出现混乱。