0

我正在设计一个老虎机项目,它对高分页面有第二个视图。在大多数情况下,除了获胜者从老虎机传递到高分页面之外,一切正常。这是我在老虎机方法中的代码:

if(win == YES)  {
    NSString *msg = nil;
    if(playerField.text.length > 0) {
        msg = [[NSString alloc] initWithFormat:@"%@", playerField.text];
    }
    NSLog(@"DEBUG");
    [(HighScorePage *)self.view addNewHighScore:msg];
    [self performSelector:@selector(playWinSound) withObject:nil afterDelay:.5];
    [msg release];
}

这是 HighScorePage 中的 addNewHighScore 方法:

-(void)addNewHighScore:(NSString *)player   {
NSMutableArray *tempArray = [[NSMutableArray alloc] init];

int i = 0;
for (NSArray *count in dynPlayerArray) {
    [tempArray addObject:[NSIndexPath indexPathForRow:i++ inSection:0]];
}
[tempArray addObject:player];
[[self highScores] beginUpdates];
[[self highScores] insertRowsAtIndexPaths:(NSArray *)tempArray withRowAnimation:UITableViewRowAnimationNone];
[[self highScores] endUpdates];

[tempArray release];    

}

在这方面还是新手,所以让我知道你的想法!谢谢!

4

2 回答 2

0

在您的评论中,您询问了如何将字符串从一个类传递到另一个类,这是答案 -

如果您想将字符串值从 B 类传递到 A 类,则在 A 类的 .h 文件中创建一个 NSMutableString 实例并将其定义为属性 -

NSString *stringVar;

@property (nonatomic, retain) NSString *stringVar;

and also synthesize this property in class A's .m file for setter & getter as-

@ synthesize stringVar;

然后在 B 类中将此字符串作为 A 类的属性访问,并分配您想要从 B 类传递给 A 类的值。

希望这会帮助你。此外,有关物业外观的更多信息 -

http://developer.apple.com/library/Mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW1enter code here

于 2011-04-07T16:12:31.413 回答
0

如果你问我,你的高分数据应该在每个人都可以访问的模型类中,例如单例。

当您的玩家获胜时,您的插槽 ViewController 应在此模型类中插入新的高分,然后使用键值观察或通知,高分视图应自行更新。

于 2011-04-06T16:26:48.007 回答