我是一名初学者,但一直在努力构建这个应用程序。从另一个问题工作,我问:mapkit and table view sample code - iPhone SDK在tableView中使用mapView注释
我能够放在一起(半)功能的tableview和mapview。但是,我不确定如何调用mapview注释来执行numberOfRowsInSection或cellForRowAtIndexPath。
cellForRowAtIndexPath我确定没有正确调用,但我想它是一个combo的numberOfRowsInSection和cellForRowAtIndexPath ..但老实说,我一直在尝试(和失败)3周,阅读我所能我问了这个问题。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//return [[mapView annotations] count];
return 1; }
所以我试图使用mapview注释的计数,但我甚至不知道这是否工作。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell =[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];
}
NSMutableArray *annotations = [[NSMutableArray alloc] init];
//i'm sure the entire block below is pretty awful but i'm at a standstill
for (MapLocation *annotation in [mapView annotations])
{
[annotations addObject:annotation];
cell.textLabel.text = [[annotations objectAtIndex:indexPath.row]title];
}
return cell; //i'm pretty sure this shouldn't be here
}
如果需要任何其他代码,以帮助解释我的情况只是让我知道。
tableView和mapView是否在同一个视图控制器中?如果您在numberOfRowsInSection中取消注释该行,会发生什么情况?它究竟如何失败?是否有编译错误,运行时错误? – Anna 2011-05-08 02:51:57
只能得到1个注释才能进入tableview,而不会在启动时崩溃。我花了几天时间,但我已经解决了这个问题,但numberOfRowsInSection仍然不是很有活力,但我可以忍受它。我会在下面发布我的解决方案。 – jamesC 2011-05-11 17:46:23