成员、学者、代码大师。我的背景与任何计算机编程都相差甚远,因此我的问题对您来说可能看起来很基本且有些微不足道。尽管如此,我似乎无法摆脱它。我已经用谷歌搜索并搜索了答案,只是让自己更加困惑。有了这个,我会请求一个简单的解释,适合像我这样的非技术人员和其他类似的人到达这个线程。
我在下面留下了一条评论,上面写着“这是问题”,指的是我的问题。
// character.h
#import <Foundation/Foundation.h>
@interface character : NSObject {
NSString *name;
int hitPoints;
int armorClass;
}
@property (nonatomic,retain) NSString *name;
@property int hitPoints,armorClass;
-(void)giveCharacterInfo;
@end
// character.m
#import "character.h"
@implementation character
@synthesize name,hitPoints,armorClass;
-(void)giveCharacterInfo{
NSLog(@"name:%@ HP:%i AC:%i",name,hitPoints,armorClass);
}
@end
// ClassAtLastViewController.h
#import <UIKit/UIKit.h>
@interface ClassAtLastViewController : UIViewController {
}
-(void)callAgain;
@end
// ClassAtLastViewController.m
#import "ClassAtLastViewController.h"
#import "character.h"
@implementation ClassAtLastViewController
- (void)viewDidLoad {
//[super viewDidLoad];
character *player = [[character alloc]init];
player.name = @"Minsc";
player.hitPoints = 140;
player.armorClass = 10;
[player giveCharacterInfo];
[player release];
// Up until here, All peachy!
[self performSelector:@selector(callAgain) withObject:nil afterDelay:2.0];
}
-(void)callAgain{
// Here is the issue, I assume that since I init the player again I loss everything
// Q1. I loss all the data I set above, where is it than?
// Q2. What is the proper way to implement this
character *player = [[character alloc]init];
[player giveCharacterInfo];
}
提前非常感谢,请记住,我的背景与鲑鱼养殖比计算机代码更相关,如果对您来说都一样,请尝试将您的答案降低到我的水平。