开发者

deleteCharactersInRange problem

I am t开发者_如何学Crying to use the deleteCharactersInRange function in a small app I wrote, but i always get an error: 'Attempt to mutate immutable object with deleteCharactersInRange:' But I defined the string i wish to use as a NSMutableString.

any ideas?

code snippets:

interface file:

#import <UIKit/UIKit.h>
@interface MyappViewController : UIViewController {
    NSMutableString *displayString;
}
@property (nonatomic, retain) NSMutableString *displayString;
@end

implementation:

#import "MyappViewController.h"
@implementation MyappViewController
@synthesize displayString;

-(void) aFunction
{
        [displayString deleteCharactersInRange:NSMakeRange([displayString length]-1,1)];
}
@end


Just because you have declared displayString as an NSMutableString, that doesn't mean that it is always going to point to an NSMutableString. You have only told the compiler that that's what's supposed to be there. Check wherever displayString actually gets set. It sounds like it must be getting set to an NSString, instead of an NSMutableString.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜