首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iPhone UIAlertView问题

iPhone UIAlertView问题
EN

Stack Overflow用户
提问于 2009-11-06 08:49:23
回答 4查看 346关注 0票数 0

好的,我有下面的代码

代码语言:javascript
复制
NSMutableArray *smartThings = [[NSMutableArray alloc] initWithCapacity:3];
NSMutableString *smartString = [NSString alloc];
int random;
int numOfThings = 1;
random = arc4random() % numOfThings;
smartString = [smartThings objectAtIndex:random];
UIAlertView *smartAlert = [[UIAlertView alloc] initWithTitle:@"Thing To Say" message:smartString delegate:self cancelButtonTitle:@"Thanks" otherButtonTitles:nil];
[smartAlert show];
[smartAlert release];

[smartThings release];

它“应该”做的是从一个字符串中创建一个UIAlertView,这个字符串是从一个字符串数组中创建的。

当我运行它并按下按钮调用这段代码时,程序崩溃了。请帮帮忙

是的,我确实连接了IB的所有连接。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2009-11-09 02:38:55

好的,这次我修复了它。我把它放在MainView.m文件中,而不是MainViewController.m文件中。

票数 0
EN

Stack Overflow用户

发布于 2009-11-06 09:07:11

在这段代码的执行过程中,smartThings是空的,即使您已经为3个项目预先分配了空间,因此-objectAtIndex将引发一个NSRangeException,如果没有被捕获,它将使程序崩溃。

此外,由于smartThing仅用作指向smartThings中对象的指针,因此不应对其进行alloc,仅将其声明为NSString*就足够了。

票数 3
EN

Stack Overflow用户

发布于 2009-11-06 09:12:50

看起来你有几个问题:

to.

  • smartString没有字符串添加到smartThings中,所以smartString没有什么可以指向的,to.

  • smartString可能应该被声明为一个NSMutableString *,of.

  • numOfThings是用于你想要改变内容的字符串,smartString是完全多余的。使用smartThings length找出smartThings

中有多少个字符串

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1684702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档