【问题标题】:loading another tableview when a tablecell of one tableview is clicked returning error:"Program received signal SIGABRT"单击一个表格视图的表格单元时加载另一个表格视图返回错误:“程序收到信号SIGABRT”
【发布时间】:2012-10-05 11:22:09
【问题描述】:

我正在创建一个应用程序,其中有两个 UIViews,在这些 UIViews 中我正在加载 Tableviews.. 当我在一个 TableView 中单击一个表格单元时,我无法将其重定向到另一个 TableView 并出现错误:程序收到信号 SIGABRT。但是如果我想在单击一个表格单元时加载一个 UIView,它会完美执行。我不明白我哪里错了...... 这是我正在写的代码

 ViewController1:
   #import ViewController2.h"

     -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

        ViewController2 *v2 = [ViewController alloc] initWithNibName:@"ViewController2" bundle:[NSBundle mainBundle]];
        [self presentModalViewController:v2 animated:NO]; **//getting error at this line**
        [v2 release];

    }
    ViewController2.h
    #import"ViewController1.h"
    - (void)viewDidLoad
    {
    [super viewDidLoad];
   tableView1 = [[UITableView alloc]initWithFrame:CGRectMake(10, 10, 320, 460)];
    tableView1.delegate = self;
    tableView1.dataSource = self;
    [self.view addSubview:tableView1]; 

   }  

无法理解导致此错误的可能原因..

【问题讨论】:

  • 不要调用 alloc 而不调用某种形式的 init... 方法...无论哪一个适合您的对象。
  • 你能简单解释一下吗?我听不懂
  • 您正在为您的 GetAppointments 对象分配内存,但没有对其进行初始化。如果您查看用于创建视图控制器的 any 示例代码,它应该具有类似 [[GetAppointments alloc] init<#...some type of initialization...>]; 的内容。
  • 我编辑了代码但还是没有成功
  • 您发布的“代码”甚至无法编译。 (ViewController2 *v2 = [ViewController alloc] initWithNibName:@"ViewController2" bundle:[NSBundle mainBundle]];) 我不会猜测我看不到的东西可能有什么问题。

标签: xcode4 uitableview


【解决方案1】:

也许这是错误

    ViewController2 *v2 = [ViewController alloc] initWithNibName:@"ViewController2" bundle:[NSBundle mainBundle]];

您分配了 ViewController 而不是 ViewController2

试试这个,我猜它应该可以工作。

    ViewController2 *v2 = [ViewController2 alloc] initWithNibName:@"ViewController2" bundle:[NSBundle mainBundle]];

【讨论】:

  • 好的,您还应该通过右键单击文件的所有者来检查 .xib 文件中的所有 IBOutlets 是否正确连接。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-04
  • 1970-01-01
  • 1970-01-01
  • 2016-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多