Ios 将UITextfield问题放入NSMutableArray

Ios 将UITextfield问题放入NSMutableArray,ios,Ios,在我意识到需要在数组中插入一个字符串之前,我一直在使用NSArray。现在我将其更改为NSMutableArray,但语法有问题。允许我在NSMutable数组中使用ComponentJoinedByString吗 NSString *item; int numofSeg; int needSeg; if (textfield.text == @"::") { numofSeg = 0; } NSMutableArray *dlist =

在我意识到需要在数组中插入一个字符串之前,我一直在使用NSArray。现在我将其更改为NSMutableArray,但语法有问题。允许我在NSMutable数组中使用ComponentJoinedByString吗

    NSString *item;
    int numofSeg;
    int needSeg;
if (textfield.text == @"::") {
        numofSeg = 0;

    }
    NSMutableArray *dlist = [[NSMutableArray alloc]init];
    //take string from textfield and split it into a list on colons.
    dlist = [textfield.text componentsSeparatedByString:@":"];
    //run through list to count how many segments. Non blank ones.
    for (item in dlist) {
        if (item != @""){
            numofSeg = numofSeg + 1;
            NSLog(@"%@",numofSeg);
        }
    }
    //determine number of segments
    needSeg = 8 - numofSeg;
    while (needSeg > 0) {
        //insert 0000 at blank spot
        [dlist insertString:@"0000" atIndex:@""];
        needSeg = needSeg - 1;
    }
    for (item in dlist) {
        if (item == @"") {
            //remove blank spaces from list
            [dlist removeAllObjects:item];
        }
    }
    //join the list of times into a string with colon
    NSString *joinstring = [dlist componentsJoinedByString:@":"];
    NSLog(@"%@",joinstring);

我认为
NSMutableArray
没有名为
insertString:atIndex:
的方法。您可能应该改用
insertObject:atIndex:

你到底得到了什么错误

编辑:

如果只使用
NSMutableArray
@“
之前插入
@“0000”
,则只需执行以下操作:

string = [string stringByReplacingOccurrencesOfString:@" " withString:@" 0000"];

或者类似的。无需使用
NSMutableArray

我不认为
NSMutableArray
有一个名为
insertString:atIndex:
的方法。您可能应该改用
insertObject:atIndex:

你到底得到了什么错误

编辑:

如果只使用
NSMutableArray
@“
之前插入
@“0000”
,则只需执行以下操作:

string = [string stringByReplacingOccurrencesOfString:@" " withString:@" 0000"];

或者类似的。无需使用
NSMutableArray

我终于找到了答案。这就是我最后用来解决这个问题的方法:

NSString *z = @"0000";
z =  [z stringByAppendingString:@""]; 

我终于明白了。这就是我最后用来解决这个问题的方法:

NSString *z = @"0000";
z =  [z stringByAppendingString:@""]; 

我的主要问题是试图在NSMutableArray中使用componentsJoinedByString。我现在有点让它工作了,但是把它转换回了NSArray。我需要在字符串@的索引处插入一个字符串。不在索引处:0。这是我用于NSArray*项=[ipv6display.text ComponentsParatedByString:@]:;我基本上需要弄清楚如何获取MutableArray数据列表并在空白处插入字符串。[dlist insertString:@“0000”atString:@”“];。在Python中,我可以这样编写:list1.insert(list1.index(“”),'0000')您所说的“在字符串的索引处@”是什么意思?你能给我举个你想做什么的例子吗?你到底遇到了什么问题?从可变数组列表中。当出现空白时,我需要插入一个字符串“0000”。上面是我的示例(insertString atIndex对我不起作用)。我还用python编写了一个有效的示例。您可以执行
IndexOfoObject:@“
以获取@”的索引,然后在刚获得的索引处执行
insertObject:atIndex:
。我的主要问题是尝试在NSMutableArray中使用由字符串连接的组件。我现在有点让它工作了,但是把它转换回了NSArray。我需要在字符串@的索引处插入一个字符串。不在索引处:0。这是我用于NSArray*项=[ipv6display.text ComponentsParatedByString:@]:;我基本上需要弄清楚如何获取MutableArray数据列表并在空白处插入字符串。[dlist insertString:@“0000”atString:@”“];。在Python中,我可以这样编写:list1.insert(list1.index(“”),'0000')您所说的“在字符串的索引处@”是什么意思?你能给我举个你想做什么的例子吗?你到底遇到了什么问题?从可变数组列表中。当出现空白时,我需要插入一个字符串“0000”。上面是我的示例(insertString atIndex对我不起作用)。我还用python编写了一个有效的示例。您可以执行
IndexOfoObject:@”“
以获取@的索引,然后在刚刚获得的索引处执行
insertObject:atIndex: