在 tableView 中使用 mapView 注释
我是一个初学者,但一直在努力构建这个应用程序。从我问的另一个问题开始: mapkit 和表视图示例代码 - iPhone SDK
我能够将(半)功能的表格视图和地图视图放在一起。但是,我不太确定如何调用mapview注释来执行numberOfRowsInSection或cellForRowAtIndexPath。
我确信 cellForRowAtIndexPath 没有正确调用,但我认为它是 numberOfRowsInSection 和 cellForRowAtIndexPath 的组合。但老实说,在我提出问题之前,我已经尝试(并失败)了 3 周,并阅读了我能读到的所有内容。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//return [[mapView annotations] count];
return 1; }
所以我试图使用地图视图注释的计数,但我什至不确定这是否有效。
-(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
。
如果需要任何其他代码来帮助解释我的情况,请告诉我
I'm a beginner but have been working really hard to build this application. Working from another question I asked: mapkit and table view sample code - iPhone SDK
I was able to put together a (semi-)functioning tableview and mapview. However, I'm not really sure how to call the mapview annotations to do numberOfRowsInSection or cellForRowAtIndexPath.
the cellForRowAtIndexPath I'm sure isn't called properly but I'm thinking its a combo of both numberOfRowsInSection and cellForRowAtIndexPath.. But honestly I've been trying (and failing) for 3 weeks and reading all I can before I asked the question.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//return [[mapView annotations] count];
return 1; }
So I was trying to use the count of the mapview annotations but I'm not even sure if this is working.
-(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
}
If any other code is needed to help explain my situation just let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我知道我一次只有 20 个注释。这仍然不理想,但它可以工作。
表视图中填充了注释信息。我通过观看 Serban Porumbescu 的 UCDavis 课程(他正在讨论表格视图和对象)找到了解决方案。
So I know that I only have 20 annotations at a time. This is still not ideal but it works
The tableview is populated with the annotation information. I found my solution by watching the UCDavis course with Serban Porumbescu (he was discussing tableviews and objects).