Ios 使用objective c时xcode 5中的tableview错误

Ios 使用objective c时xcode 5中的tableview错误,ios,objective-c,xcode,uitableview,Ios,Objective C,Xcode,Uitableview,我写了一个程序在iPad上显示表格。我的程序如下: @implementation ViewController -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 5; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndex

我写了一个程序在iPad上显示表格。我的程序如下:

@implementation ViewController

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cell"];


    cell.textLabel.text=@"this is a cell";

    return cell;
}
没有问题。但当我运行程序时,线程将显示如下:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}
#导入
#导入“AppDelegate.h”
int main(int argc,char*argv[])
{
@自动释放池{
返回UIApplicationMain(argc、argv、nil、NSStringFromClass([AppDelegate类]);
}
}

线程1:signal sigbabart

需要堆栈跟踪才能真正知道,但很有可能您的应用程序因内存问题而被弹出。您应该在tableView中使用可重用的单元格,以将发生这种情况的可能性降至最低


您需要为原型单元分配单元标识符,然后可以调用
dequeueReusableCellWithIdentifier:
,并在
cellForRowAtIndexPath:
中传递该标识符。这样,当单元格滚动到屏幕外时,它们将被重新用于即将到来的单元格。您可能会看到性能和滚动速度方面的巨大改进。如果这不能解决问题,那么您的应用程序中还有一些其他关键问题,您可以使用仪器进行诊断。

TableViewCell
分配问题。如果单元格可用,我们需要重新使用,否则我们需要创建一个

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        static NSString * identifier = @"cellIdentifier";
//Cell reusing..
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell)
        {
// Cell creation
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
    cell.textLabel.text=@"this is a cell";
    return cell;
} 

最有可能的问题是,你没有遵循苹果提供的指导方针

总是在实践中创造新的细胞是不好的。 将单元格保留在视图控制器的数组中是一种不好的做法。 忽略文档更糟糕

请尝试以下代码:

@implementation ViewController

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString* reuseIdentifier = @"cell";
   UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
   if (!cell)
   {
       cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:reuseIdentifier];
   }
   cell.textLabel.text=@"this is a cell";

return cell;
}


如果我把这个:UITableViewCell*cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@“cell”];我得到了如下错误:使用未声明的标识符:uitableViewCellStyleDefaultReuseIdentifier这是因为您需要注册标识符。同样应该是,
YourCellSubclass*cell=[self.tableView dequeueReuseableCellWithIdentifier:@“yourdidentifier”
]为什么不先阅读一些文档/教程/示例?你提供的代码作为一个例子,只是大声尖叫:“嘿,我在这里!我没有读任何文档,只是想射中我自己的脚!”@eagle.dan.1349也许你应该学会发表更有成效的评论
Madhu M
我已经删除了
xcode
标记,因为这与
xcode
本身无关,以后使用此标记时请小心。请同时共享stacktrace,是否尝试添加异常断点?应用程序不会在
main
上崩溃,就像它显示了它到达那里的原因一样,是因为你没有捕获正在抛出的异常。@大力水手如果我理解正确,StackOverflow是一个错误的地方,在RTFM之前问一个问题“为什么它把我整条腿都炸了?”。我在示例中看到的代码违反了iOS编码标准/准则。我尝试了这个。但我得到了与我在问题中提到的相同的错误。GABRT是一般性崩溃,由于未捕获的异常“NSUnknownKeyException”,你能用控制台监测应用程序中显示的完整错误报告更新吗?原因:“[setValue:forUndefinedKey:]:此类不符合key textLabel的键值编码。“***第一次抛出调用堆栈:使用自定义单元格或基本单元格。使用基本单元格并删除所有不必要的输出。或尝试使用新的tableView