好的,我有下面的代码
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的所有连接。
发布于 2009-11-09 02:38:55
好的,这次我修复了它。我把它放在MainView.m文件中,而不是MainViewController.m文件中。
发布于 2009-11-06 09:07:11
在这段代码的执行过程中,smartThings是空的,即使您已经为3个项目预先分配了空间,因此-objectAtIndex将引发一个NSRangeException,如果没有被捕获,它将使程序崩溃。
此外,由于smartThing仅用作指向smartThings中对象的指针,因此不应对其进行alloc,仅将其声明为NSString*就足够了。
发布于 2009-11-06 09:12:50
看起来你有几个问题:
to.
中有多少个字符串
https://stackoverflow.com/questions/1684702
复制相似问题