【发布时间】:2014-12-28 06:23:05
【问题描述】:
我有一个带有 tableview 的 table view 控制器,我在 storyboard 中设置了一个从 mapViewController 到它的 push segue。当用户触摸 ios 提供的注解标注时,会调用 calloutAccessoryControllTapped 函数,并通过称为
的通知间接调用 [self performSegueWithIdentifier:@"SequeToConversationList" sender:self];
这很好用。
但是,我将 ios 提供的标注替换为在 XIB 中布置的自定义标注。它有一个按钮,其操作会导致执行上面的同一行代码,并且发生对 tableView 的 Segue,但是 tableViewController 的 cellForRowAtIndexPath 永远不会被调用。但是 titleForHeaderInSection 确实被调用,这表明它正在充当 UITableViewDataSource。
有人有什么想法吗?
每个代码请求:
.h:
#import <UIKit/UIKit.h>
@interface PhListTableViewController : UITableViewController <UITableViewDataSource,UITableViewDelegate>
@end
.m:
#import "PhListTableViewController.h"
#import "PhSettings.h"
@interface PhListTableViewController ()
@end
@implementation PhListTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
PhSettings *settings=[PhSettings getInstance];
settings.currentViewController = CONV_LIST;
//...
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
PhSettings *settings=[PhSettings getInstance];
return [settings.myUUIDsList count];
}
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return @"Active:";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
// Configure the cell...
PhSettings *settings=[PhSettings getInstance];
NSMutableString *s = [NSMutableString string];
[s appendString:@"Alias:"];
[s appendString:[[settings.myUUIDsList objectAtIndex:indexPath.row] userAlias]];
[s appendString:@"Category: "];
[s appendString:[[settings.myUUIDsList objectAtIndex:indexPath.row] category]];
cell.textLabel.text=s;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//indexPath.row
// ...
}
@结束
【问题讨论】:
-
您是否在您的 XIB 中链接了委托和数据源?
-
XIB 仅用于注释的自定义标注。它与启动 segue 没有任何直接关系。这是通过通知完成的。 IE。用户在自定义标注中选择一个按钮,会发生一些往返服务器的事情,当回调完成时,会向 mapViewController 发送通知以启动 segue。
-
你能贴出你自定义tableView的代码吗?这样我们就可以深入挖掘了。
-
那么在你
replaced the ios supplied callout之前,一切正常吗? -
是的,在将标注替换为自定义标注之前一切正常,但是......可能 numberOfRowsInSection 返回 0。现在检查。
标签: ios uitableview segue