Я работаю с NSMutableString и испытываю некоторые трудности.Приложение закрывается всякий раз, когда я пытаюсь получить к нему доступ, и оно не говорит, что в NSLog что-то не так.
Я настроил строку в методе вида «загрузка», чтобы моя строка могла сохранять свою информацию, а не сбрасываться, но я не верю, что мои знания об этом верны.Любая помощь будет отличной.Спасибо!
#import <UIKit/UIKit.h>
@class rootViewController;
@interface Numpad : UIViewController {
rootViewController *viewController;
UIButton *one;
UIButton *two;
UIButton *three;
NSInteger *loggedNumbers;
NSMutableString *numberString;
}
-(IBAction)buttonClicked:(id)sender;
@property (nonatomic, retain)IBOutlet UIButton *one;
@property (nonatomic, retain)IBOutlet UIButton *two;
@property (nonatomic, retain)IBOutlet UIButton *three;
@property (nonatomic, retain) rootViewController *viewController;
@end
и .m
#import "Numpad.h"
@implementation Numpad
@synthesize viewController, one, two, three, four, five, six, seven, eight, nine, zero;
- (void)initString{
}
- (IBAction)buttonClicked:(id)sender{
int stringLength = [numberString length];
//NSLog(@"Number String before Switch: %@", numberString);
switch (((UIButton*)sender).tag){
case 1:
{
[numberString insertString: @"1" atIndex: stringLength];
}
break;
case 2:
{
[numberString insertString: @"2" atIndex: stringLength];
}
break;
case 3:
{
[numberString insertString: @"3" atIndex: stringLength];
}
break;
default:
break;
}
double myDouble = [numberString doubleValue];
int myInt = (int)(myDouble + (myDouble>0 ? 0.5 : -0.5));
NSLog(@"Number String: %@", numberString);
NSLog(@"After int applied: %i", myInt);
}
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
numberString = [[NSMutableString stringWithString: @""];
[super viewDidLoad];
}