Members, scholars, code gurus. My background is far from any computer programming thus my question may seems basic and somewhat trivial to you. Nevertheless it seems that I can t put my head around it. I have googled and searched for the answer, just to get myself confused even more. With that, I would kindly ask for a simple explanation suitable for a non technical person such as myself and for other alike arriving to this thread.
我在谈到我的问题时,对以下案文发表了意见。
// 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];
}
很多人预先感谢,但愿记住,我的背景与 Sal鱼的繁殖有关,而不是与计算机法典有关,如果你与你一样,试图把你的答复降低到我的水平。