Iphone TableView没有加载数据?
在我的地图应用程序中,我在主屏幕上有段控制器,使用它我有地图视图和表格视图(两者都是UIView)。我已经尝试了所有方法,但是我的数据没有加载到我的tableview中。这是我的tableview代码。这里的标记是我的xml文件中的属性,它包含展厅名称,我能够解析它。 .h文件 在我的tableview标题中,它正确显示数据计数,但不显示数据。 我已将委托、数据源、表格视图连接到HViewController的文件所有者,我在其中放置了上述代码。请指出我错的地方。我正在解析XML文件并在控制台alos中获取数据,我可以在地图上显示它。但我无法在tableview中加载数据。Iphone TableView没有加载数据?,iphone,uitableview,Iphone,Uitableview,在我的地图应用程序中,我在主屏幕上有段控制器,使用它我有地图视图和表格视图(两者都是UIView)。我已经尝试了所有方法,但是我的数据没有加载到我的tableview中。这是我的tableview代码。这里的标记是我的xml文件中的属性,它包含展厅名称,我能够解析它。 .h文件 在我的tableview标题中,它正确显示数据计数,但不显示数据。 我已将委托、数据源、表格视图连接到HViewController的文件所有者,我在其中放置了上述代码。请指出我错的地方。我正在解析XML文件并在控制台a
尝试将
[\u tableView reloadData]
移动到视图将出现
在视图中重新加载表视图的数据将出现
,而不是视图加载
。我不能告诉你这会产生影响的确切原因,尽管我能想到几个。无论如何,值得一试
编辑:对评论的答复
titleForHeaderInSection:
,则存在连接到表视图的数据源。因此,问题不是缺少数据源连接titleForHeaderInSection:
被调用,但cellForRowAtIndexPath:
不是因为没有空间显示任何单元格。请注意,这只是一个猜测,但这是我能想到的唯一会导致您描述的行为的场景。您发布的代码看起来还可以,不过有点复杂
reloadData
应该在视图中出现。苹果工程师在创建UITableViewController类时就是这么说的。所以,换言之,你必须相信你比他们知道得更多
我已经试过你的解决办法了,它不起作用。我检查我的-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{}方法未通过设置断点或NSLoging调用。如何解决此问题???另外,以下方法在tableview的底部显示数据计数-(NSString*)tableview:(UITableView*)tableview标题ForHeaderInSection:(NSInteger)节{if(section==0)返回[NSString stringWithFormat:NSLocalizedString(@“ShowRooms[%d]”,@“ShowRooms format”),[appDelegate.markers count];}(:(:)(是的,你的猜测是正确的…我错误地有两个我以前没有观察到的tableview。我删除了一个tableview。这解决了我的一个问题。现在我得到了上面的数据计数。但没有得到要显示的数据:(仍然是我的cellForRowAtIndexPath:没有通过设置断点来调用…我按照u的建议删除了一个不必要的表视图,从而重新连接了所有内容。只在顶部使用空白列表获取数据计数问题如下。Interface Builder为您创建了一个表视图。但是,之后,在
viewDidLoad
中,您可以创建新表视图&将ivar设置为新表视图,删除与Interface Builder表视图的连接。但是,您不需要调用addSubview:
来添加新表视图。因此,新表视图根本不显示,而Interface Builder表不再连接到IBAR。总之,您不需要这样做o alloc/init如果您已经在Interface Builder中创建了一个表视图,那么它将在代码中显示。我刚刚从以下链接中获得了上述问题的最佳答案:)必须看到…..这是非常小的解决方案,产生了很大的不同。感谢Louis和salo.dm的跟进。salo.dm帮助我解决了下面答案中的一些错误。再次感谢您的支持。
@interface HViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> {
UITableView *_tableView;
}
@property (nonatomic, retain) IBOutlet UITableView *_tableView;
@end
@synthesize tableView;
- (void)viewDidLoad {
appDelegate = (HAppDelegate *)[[UIApplication sharedApplication] delegate];
[segmentedControl addTarget:self action:@selector(segmentAction:)
forControlEvents:UIControlEventValueChanged];
}
- (void)viewWillAppear:(BOOL)animated
{
self._tableView.rowHeight = 80.0;
[_tableView reloadData];
}
-(void)segmentAction:(id)sender;{
UISegmentedControl* segCtl = sender ;
if( [segCtl selectedSegmentIndex] == 0 )
{
NSLog(@"segmentAction mapView");
mapView.hidden = NO;
_tableView.hidden = YES;
//[ self.view addSubview:mapView] ; // adding view to segmentindex 0
}
if( [segCtl selectedSegmentIndex] == 1 )
{
NSLog(@"segmentAction _tableview");
_tableView.hidden = NO;
mapView.hidden = YES;
//[ self.view addSubview:_tableview] ;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"appDelegate.markers _tableview");
return [appDelegate.markers count];
}
//method to print row(showroom count on Header)
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section {
if(section == 0)
return [NSString stringWithFormat:NSLocalizedString(@"ShowRooms[%d]", @"Showroom format"), [appDelegate.markers count]];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSUInteger const kShowroomNameLabelTag = 2;
UILabel *ShowroomNameLabel = nil;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
ShowroomNameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(50, 1, 300, 20)] autorelease];
ShowroomNameLabel.tag = kShowroomNameLabelTag;
ShowroomNameLabel.font = [UIFont boldSystemFontOfSize:18];
[cell.contentView addSubview:ShowroomNameLabel];
NSLog(@"UITableViewCell.markers _tableview");
}
else
{
ShowroomNameLabel = (UILabel *)[cell.contentView viewWithTag:kShowroomNameLabelTag];
}
marker *aMarker = [appDelegate.markers objectAtIndex:indexPath.row];
//ShowroomNameLabel.text = aMarker.name;
ShowroomNameLabel.text= [NSString stringWithFormat:@"ShowroomName= %@", aMarker.name];
return cell;
}