我正在按照惯例制作一个不错的应用程序,然后就会发生这种情况!你在我的应用程序中旋转命运之轮,当旋转动画完成时,应用程序应该随机化一个数字,并显示匹配为数字索引的卡.
这些卡存储在NSMutableArray中,在第一次调用时工作正常.例如.当应用程序随机化数字"1"卡号1被调用并显示没有问题!但是一旦随机发生器再次点击"1",应用程序就会在下面指定的行上崩溃.
这是代码,请帮帮我:)
NSNumber *cardNumber;
cardNumber = [NSNumber numberWithUnsignedInt:arc4random()%[appDelegate.cardArray count]];
NSLog(@"%@", cardNumber);
SpinCard *selectedCard = [appDelegate.cardArray objectAtIndex:[cardNumber doubleValue]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[snurrKnapp setAlpha:100];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:cardView cache:YES];
[UIView commitAnimations];
[snurrKnapp setEnabled:YES];
if(![cardTitle.text isEqualToString:selectedCard.cardTitle]) { //Crashes here
[cardTitle setText:selectedCard.cardTitle]; //If I remove the if-case it crashes here
[cardContent setText:selectedCard.cardContent];
}
[selectedCard release];
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
2011-04-21 23:10:54.296 Snurra Flaskan[947:707] 0
2011-04-21 23:10:58.794 Snurra Flaskan[947:707] 2
2011-04-21 23:11:02.691 Snurra Flaskan[947:707] 1
2011-04-21 23:11:08.977 Snurra Flaskan[947:707] 2
warning: Unable to read symbols for …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来比较两个字符串,看看第二个字符串是否包含第一个中列出的字符(字母,数字,其他),让我解释一下:
例如:想象一个只有数字的密码,允许使用"*":参考链(1):"*0123456789" NSString格式,无NSArray
工作链(2)="156/15615 = 211" NSString格式,
我怎么知道我的链2包含2个字符(/ =)哪个不在我的链1中?
为了简化允许的管理字母,我不想NSArray用来管理链,例如函数调用:
BOOL unauthorized_letter_found = check(work_chain, reference_chain);
Run Code Online (Sandbox Code Playgroud)
你必须通过"for" NSPredicate,等等?
PS:我在MAC OS上,而不是iOS,所以我无法使用NSRegularExpression.
嗨,只是想知道是否可能,因为用户正在输入一串数字,以便每隔字符串第5个字符动态添加一个连字符...
任何帮助将不胜感激.
我想知道如何在iPhone中的字符串中保存数组(Objective-c).因为我有一个数据数组
数组[0] = 01数组[1] = 02数组[2] = 03数组[3] = 04
现在我想将它保存在这样的字符串中
NSString *string = @"01, 02, 03, 04";
Run Code Online (Sandbox Code Playgroud)
如果你有一些想法,请帮助我,我是这个领域的新手.
提前.
如何连接int(例如:) 4和字符串(例如:)@"/12"进行打印?
我可以将int它转换为NSString格式,但我不知道如何@"/12"在int的值之后添加它.
我有和NSArray有5个字符串元素,填充我的iPhone应用程序的UITableView.
一切正常,但有时我的数组的第一个字符串丢失,我无法弄清楚为什么.
这是我的代码:
arrayList = [[NSArray alloc] initWithObjects: @"My First String",
@"My Second String",
@"My Third String",
@"My Forth String",
@"My Fifth Sring",
nil];
Run Code Online (Sandbox Code Playgroud)
有时只是没有显示的元素是My First String
其实我正在使用Cocoa With Love的示例代码.谢谢大家帮助我!
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
#if USE_CUSTOM_DRAWING
const NSInteger TOP_LABEL_TAG = 1001;
// const NSInteger BOTTOM_LABEL_TAG = 1002;
UILabel *topLabel;
// UILabel *bottomLabel;
#endif
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
//
// Create the cell.
//
cell = …Run Code Online (Sandbox Code Playgroud) 在操作我的一些NSString物体时,我得到了垃圾值.我认为问题源于我对NSString在基本级别的工作方式的误解.下面,我有一个对象,它有一个字符串指针作为合成属性.当我尝试直接将其注销时,编译器会给我一个警告,但它会注销我期望的值.在下一行,我尝试以正确的方式记录该字符串,但我最终得到了垃圾.
代码段
MyObject *object = [self.objects objectAtIndex:indexPath.row];
NSString *myString = object.myString;
NSLog(myString); // format not a string literal and no formal arguments
NSLog(@"formatted = %s", myString);
Run Code Online (Sandbox Code Playgroud)
产量
2011-05-16 13:06:51.137 MyProgram[917:207] thisValueIsGood
2011-05-16 13:06:51.138 MyProgram[917:207] formatted = `å
Run Code Online (Sandbox Code Playgroud)
这个问题已经滚雪球到其他使用这个最终字符串的函数上.当我将该字符串与其他字符串连接起来时,我会得到更多的垃圾.
我写了以下代码:
if (depSelectedIndice > -1 && comSelectedIndice> -1)
{
NSLog(@"depart elemet : %d ",depSelectedIndice);
NSLog(@"depart elemet : %d ",comSelectedIndice);
NSLog(@"ok1");
NSString *choosedDate =[NSString stringWithFormat:@"%@%@",[deparatureDates objectAtIndex:depSelecif (depSelectedIndice > -1 && comSelectedIndice> -1)
{
NSLog(@"depart elemet : %d ",depSelectedIndice);
NSLog(@"depart elemet : %d ",comSelectedIndice);
NSLog(@"ok1");
NSString *choosedDate =[NSString stringWithFormat:@"%@%@",[deparatureDates objectAtIndex:depSelectedIndice], [goingBackDates objectAtIndex:comSelectedIndice]];
NSLog(@"0000000000001");
NSLog(@" number of element : %d", [allCombinations count]);
// for (int j=0; j<[allCombinations count]; j++)
// {
// NSLog(@"111111111111111111");
// // NSString *date = [[allCombinations objectAtIndex:j] objectForKey:@"keydate"];
// NSLog(@"22222222222222222222"); …Run Code Online (Sandbox Code Playgroud) 好的,所以我从在线数据源中提取给定邮政编码的地址列表.请求向我发送了一个数组数组的JSON,在数组的第一层内是字符串数组.
这些包含例如.
Addressline1, Addressline2, Town, Country, Postcode
Run Code Online (Sandbox Code Playgroud)
我需要为每个地址添加所有这些字符串,这样我每个地址只有一个工作字符串.但是,有时@""阵列中有一个空白字段.
这是我的for循环.
id object;
NSString *startString = [NSString stringWithString:@"testStart:"];
for (object in arrayContainingAddress) {
NSString *useableString = [NSString stringWithFormat:@"%@", object];
if (![useableString isEqualToString:@""]) {
NSLog(@"%@", useableString);
[startString stringByAppendingString:useableString];
NSLog(@"%@", startString);
}
}
NSLog(@"%@", startString);
Run Code Online (Sandbox Code Playgroud)
问题是,startString总是以'testStart:'结尾注销,但useableString记录包含正确的地址,城镇等,for循环中的startString NSLog也只是注销为'testStart:'.
整个代码块都位于while循环中,该循环为每个地址切换适当数组的'arrayContainingAddress'.
"id对象"的原因是我的JSON转换有时会将值转换为NSNumbers(地址的第一行可能是门牌号,例如123),因此我在此处防止崩溃.
TLDR:在我的for循环中没有附加字符串'startString'.
我正在尝试创建一个NSDictionary对象,其中的键定义了歌曲的编号以及信息.我在尝试定义传入方法的NSNumber时遇到上述错误:
+(NSDictionary *) initWithMPMediaItem:(MPMediaItem *) song andSongNumber: (NSNumber *)songCount{
NSString *songKey = @"%@ Song Title", songCount;
Run Code Online (Sandbox Code Playgroud) nsstring ×10
objective-c ×7
iphone ×5
cocoa ×2
cocoa-touch ×2
ios ×2
nsnumber ×2
string ×2
arrays ×1
comparison ×1
hyphenation ×1
nsarray ×1
nspredicate ×1
random ×1
xcode ×1