标签: nsstring

当随机数显示两次时,我的对象崩溃iPhone应用程序!:(

我正在按照惯例制作一个不错的应用程序,然后就会发生这种情况!你在我的应用程序中旋转命运之轮,当旋转动画完成时,应用程序应该随机化一个数字,并显示匹配为数字索引的卡.

这些卡存储在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)

iphone random xcode nsnumber nsstring

1
推荐指数
1
解决办法
201
查看次数

检查NSString是否包含来自不同NSString的字符

我正在寻找一种方法来比较两个字符串,看看第二个字符串是否包含第一个中列出的字符(字母,数字,其他),让我解释一下:

例如:想象一个只有数字的密码,允许使用"*":参考链(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.

cocoa objective-c nsstring nspredicate

1
推荐指数
2
解决办法
5138
查看次数

如何使用stringWithFormat动态地将连字符添加到我的字符串中

嗨,只是想知道是否可能,因为用户正在输入一串数字,以便每隔字符串第5个字符动态添加一个连字符...

任何帮助将不胜感激.

iphone hyphenation nsstring stringwithformat ios

1
推荐指数
1
解决办法
1353
查看次数

如何在iphone中将数组保存为字符串?

我想知道如何在iPhone中的字符串中保存数组(Objective-c).因为我有一个数据数组

数组[0] = 01数组[1] = 02数组[2] = 03数组[3] = 04

现在我想将它保存在这样的字符串中

NSString *string = @"01, 02, 03, 04";
Run Code Online (Sandbox Code Playgroud)

如果你有一些想法,请帮助我,我是这个领域的新手.

提前.

arrays cocoa-touch nsstring ios

1
推荐指数
1
解决办法
7535
查看次数

连接int和string

如何连接int(例如:) 4和字符串(例如:)@"/12"进行打印?

我可以将int它转换为NSString格式,但我不知道如何@"/12"在int的值之后添加它.

objective-c string-formatting nsstring

1
推荐指数
1
解决办法
3440
查看次数

Objective-C:有时缺少NSArray的第一项

我有和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)

iphone cocoa-touch objective-c nsstring nsarray

1
推荐指数
1
解决办法
6892
查看次数

当我收到警告时,NSLog仅打印正确的值

在操作我的一些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)

这个问题已经滚雪球到其他使用这个最终字符串的函数上.当我将该字符串与其他字符串连接起来时,我会得到更多的垃圾.

objective-c nsstring

1
推荐指数
1
解决办法
138
查看次数

比较objective-C中的2个字符串

我写了以下代码:

   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)

string iphone comparison objective-c nsstring

1
推荐指数
1
解决办法
2万
查看次数

麻烦在for循环中追加字符串(NSString)

好的,所以我从在线数据源中提取给定邮政编码的地址列表.请求向我发送了一个数组数组的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'.

string iphone cocoa objective-c nsstring

1
推荐指数
1
解决办法
1418
查看次数

NSString错误 - 无法静态分配接口类型

我正在尝试创建一个NSDictionary对象,其中的键定义了歌曲的编号以及信息.我在尝试定义传入方法的NSNumber时遇到上述错误:

+(NSDictionary *) initWithMPMediaItem:(MPMediaItem *) song andSongNumber: (NSNumber *)songCount{

NSString *songKey = @"%@ Song Title", songCount;
Run Code Online (Sandbox Code Playgroud)

objective-c nsnumber nsstring

1
推荐指数
1
解决办法
3531
查看次数