在iOS 5 TableViewController没有滚动,也没有调用didSelectRowAtIndexPath
我已经使用XCode 4.2版本升级到iOS 5。 因为我已经升级,我无法创建合适的工作台视图控制器。在iOS 5 TableViewController没有滚动,也没有调用didSelectRowAtIndexPath
1)表视图被示出在该设备上,但是当我尝试向上滚动,它崩溃没有任何错误信息
2)当我尝试选择一个单元格,didSelectRowAtIndexPath方法不被调用。
NOTE: the same code was workign for me before upgrating to iOS5.
这是TableViewController.m代码文件
#import "CTableViewController.h"
@implementation CTableViewController
@synthesize arrNames;
-(id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
NSLog(@"CTableViewController::initWithStyle");
// Custom initialization
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
arrNames = [[NSMutableArray alloc]initWithObjects:@"Peter Frank Brauer",@"Robert Schneider",@"Winfried Walter Kem",@"Eugen Germen Bachle",@"Clara Weib",@"Heinz Guther Winkler",@"Roland Bendel",@"Swen Aschemeyer",@"Patrick Bodingmeier",nil];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.arrNames count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.textLabel.text = [self.arrNames objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:16];
NSLog(@"CTableViewController::cellForRowAtIndexPath");
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"called didSelectRow method");
}
@end
谢谢,请帮忙 的Suse
如果它的崩溃没有任何错误信息比它可能是一个内存管理问题而且这很可能是因为代码的其他部分发生,或者甚至是因为格式错误的nslog。
编译器似乎没有注意到一些显而易见的事情,例如为int设置一个分数值,这会立即崩溃应用程序,但没有任何有意义的错误消息。
尝试寻找代码中的世俗事物,而不仅仅是在tableView实现中。
另外,是否有任何具体的原因,你是用alloc,init(非autorelease)而不是arrayWithObjects填充你的arrNames?
另外:运行静态分析仪!它可能有帮助。按住运行按钮,将会弹出一个分析按钮。
我在这里得到的崩溃错误是EXC_BAD_ACCESS。最有可能的是由于内存管理,因为那个darn ARC,我不能使用autorelease命令。 – 2012-09-05 02:44:38
我将您的源代码复制并粘贴到新项目中。有一些东西跳到我身上。
您是UITableViewController的子类。尝试只是继承UIViewController,并删除你的initWithStyle方法。
请确保在nib中,tableview委托和数据源都附加到文件的所有者。
如果你仍然遇到崩溃,那么这段代码不是你的问题。
我和他有同样的问题。但我无法解决它,我同意代码不是问题。但是,我看到所有的断点和崩溃日志,我不知道如何解决这个问题:( – 2012-09-05 02:41:46
在我的情况下,它是控制器实例在本地声明,它正在失去委托,所以我宣布实例在标题和一切正常。
如何在首先发生碰撞时选择行?
顺便说一下,代码似乎不是问题。 试试这个重新启动您的Xcode后:
- 进入到管理
- 选择项目选项卡
- 单击您要打开的项目和DELETE派生数据。
然后等待重新索引。 (您可以看到顶部条形码编码和具有新索引目标的代码)。
所以像往常一样干净的所有目标和建设。
它为我在类似案件。 希望它有帮助。
可悲的是,这并不适合我。 – 2012-09-05 02:40:31
我有完全相同的问题,并修整解决现在2周,并没有运气:(如果有人有解决方案请帮助! – 2012-08-01 18:23:00
当我使用'UITableView'子类,我也得到了同样的问题。我它的工作我已经改变了类UIViewController'的'子类之后。我没有在代码中没有其他变化。 – Ananth 2012-08-03 09:34:19
你已经启用了“所有异常”断点?这应该给你,为什么应用程序崩溃详细 @Ananth如果你在一个UIViewController(而不是UITableViewController)中使用UITableView,你需要自己设置委托和数据源(你也应该声明你的视图控制器符合UITableViewDelegate和UITableViewDataSource协议) – Moxy 2012-08-05 00:30:34