由数组引起的SIGABRT

发布于 2024-12-15 13:21:55 字数 1286 浏览 0 评论 0原文

当我单击 nextIdea() 按钮时,出现错误,突出显示 int retVal = UIApplicationMain(argc, argv, nil, nil) 并显示 SIGABRT

- (IBAction)nextIdea:(id)sender
{
int index = arc4random() % ideaArray.count;
ideaTextView.text = [NSString stringWithFormat:@"%@",[ideaArray objectAtIndex:index]];
}

- (void)viewDidLoad
{
[super viewDidLoad];

PFQuery *query = [PFQuery queryWithClassName:@"Ideas"];
[query whereKey:@"Hidden" equalTo:@"entry"];
[query getObjectWithId:@"Idea"];
ideaArray = [[[NSArray alloc] init] autorelease];
//  ideaArray = [query findObjects];
ideaArray = [NSArray arrayWithObjects:@"one", @"two", nil];
}

我已经尝试解决这个问题几个小时了但没有运气。

ideaArray 在标头中声明并合成 btw

确切的错误消息:

[15842:f803] application:didFailToRegisterForRemoteNotificationsWithError: Error Domain=NSCocoaErrorDomain Code=3010 "remote notifications are not supported in the simulator" UserInfo=0x6a5e500 {NSLocalizedDescription=remote notifications are not supported in the simulator}

在设备上时,错误读取:

Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x19f4f0 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}

When I click the button for nextIdea(), I get an error that highlights int retVal = UIApplicationMain(argc, argv, nil, nil) and says SIGABRT

- (IBAction)nextIdea:(id)sender
{
int index = arc4random() % ideaArray.count;
ideaTextView.text = [NSString stringWithFormat:@"%@",[ideaArray objectAtIndex:index]];
}

- (void)viewDidLoad
{
[super viewDidLoad];

PFQuery *query = [PFQuery queryWithClassName:@"Ideas"];
[query whereKey:@"Hidden" equalTo:@"entry"];
[query getObjectWithId:@"Idea"];
ideaArray = [[[NSArray alloc] init] autorelease];
//  ideaArray = [query findObjects];
ideaArray = [NSArray arrayWithObjects:@"one", @"two", nil];
}

I've been trying to figure this out for hours but have no luck.

ideaArray is declared in the header and synthesized btw

Exact error message:

[15842:f803] application:didFailToRegisterForRemoteNotificationsWithError: Error Domain=NSCocoaErrorDomain Code=3010 "remote notifications are not supported in the simulator" UserInfo=0x6a5e500 {NSLocalizedDescription=remote notifications are not supported in the simulator}

When on the device, error reads:

Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x19f4f0 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日记撕了你也走了 2024-12-22 13:21:55

除非将 ideaArray 存储为类变量,否则您将无法从 nextIdea: 方法访问它。

  1. 使 ideaArray 成为该类的属性
  2. 分配数组时,请使用 self.ideaArray = [NSArray arrayWithObjects:@"one", @"two", nil]; 表示法。 self 将指您创建的属性。
  3. 使用 self.ideaArraynextIdea: 方法访问数组。

Unless you store the ideaArray as a class variable, you will not be able to access it from the nextIdea: method.

  1. Make the ideaArray a property of the class.
  2. When you allocate the array, use the self.ideaArray = [NSArray arrayWithObjects:@"one", @"two", nil]; notation. The self will refer to the property you have created.
  3. Access the array from the nextIdea: method using self.ideaArray.
﹏雨一样淡蓝的深情 2024-12-22 13:21:55

该属性设置为(非原子,分配),只需将分配更改为复制,并且它可以工作

The property was set to (nonatomic, assign), just changed assign to copy, and it works

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文