English 中文(简体)
我为什么在试图从可移动的阿雷拉搬走时,“向不可改变的物体发送的改变方法”?
原标题:Why am I getting : "mutating method sent to immutable object" when trying remove from MutableArray?

我可以指出,我为什么在《刑法》中被带往可变物体的突变方法。 阵列必须是不可改变的,但我不知道为什么。

接口:

    @interface SectionsViewController : UIViewController<UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate> {

    UITableView *table;
    UISearchBar *search;
    NSMutableDictionary *names;
    NSMutableArray *keys;

}
@property (nonatomic, retain) IBOutlet UITableView *table;
@property (nonatomic, retain) IBOutlet UISearchBar *search;
@property (nonatomic, retain) NSDictionary *allNames;
@property (nonatomic, retain) NSMutableDictionary *names;
@property (nonatomic, retain) NSMutableArray *keys;

-(void) resetSearch;
-(void) handleSearchForTerm:(NSString *)searchTerm;

@end

通知称姓名为动产。

下面一行将排除例外情况。

[array removeObjectsInArray:toRemove];

此处所用方法完全是:

-(void)handleSearchForTerm:(NSString *)searchTerm
{
    NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init];
    for(NSString *key in self.keys)
    {
        NSMutableArray *array = [names valueForKey:key];
        NSMutableArray *toRemove = [[NSMutableArray alloc] init];

        for(NSString *name in array)
        {
            if([name rangeOfString:searchTerm
                           options:NSCaseInsensitiveSearch].location == NSNotFound)
                [toRemove addObject:name];
        }
        if([array count] == [toRemove count])
            [sectionsToRemove addObject:key];

        [array removeObjectsInArray:toRemove];
        [toRemove release];
    }
    [self.keys removeObjectsInArray:sectionsToRemove];
    [sectionsToRemove release];
    [table reloadData];
}

I am assigning array from the result of this [names valueForKey:key]; array is of type MutableArray What am I missing?

感谢!

最佳回答

www.un.org/chinese/ga/president 您寄至<条码> NSMutable Array。

您可以将结果投到<代码>(NS MutableArray *),但我个人希望得到一份副本:

NSMutableArray *array = [[[names valueForKey:key] mutableCopy] autorelease];
问题回答

变量作为<代码>NStable Array固定分类,但分配给变量的物体似乎不是。 NSMutable Array。 变数类型只是汇编者在检查类型和选择方法签名时使用的指针——你们仍然必须谨慎地确保你重新实际分配变数所说的类型。





相关问题
How do you create UIBarButtonItems with a radio interface?

I have a UIToolbar that needs three buttons in a radio style, meaning that of the three, only one button can be pushed at a time. The documentation makes reference to the possibility of setting up ...

iPhone settings bundle

I want to allow the user to enter a valid date using the iPhone’s settings application. I have experimented with many of the PreferenceSpecifiers data node types including date. I have two issues: ...

Circular #import/@class problem in ObjectiveC

I m going to use an example to properly illustrate my confusion. I can t quite wrap my head around this. In Cocoa touch, we have UIViewController and its subclass, UINavigationController. Now, UIVC ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Cocoa-Touch: issue looping MPMoviePlayerController

I have an app which has to load some data at startup, so I want to display a splash-screen animation. I m using the MPMoviePlayerController to play a m4v file. The movie has it s background set to [...

Iphone sequential animation with setAnimationDelay

I m trying to chain animation events. The application I m coding for work has a multiple choice quiz. First you pick your multiple choice answer. The quiz view fades away. Then a label ("correct" or "...

热门标签