我已经遵循类似SO问题的建议,似乎无法使这项工作成功。我正在开发一款游戏,报告最后得分,然后是最后得分的分享按钮。
这适用于iPhone,我的iPad代码如下所示。一旦我点击“共享”按钮,iPad版本就会崩溃。此代码来自this tutorial on Coding Explorer。
iPad代码(不起作用)
- (IBAction)shareButton:(id)sender;
{
NSString * text = [NSString stringWithFormat:@"I just scored %li in Flying Freddy. Think you can beat it? https://itunes.apple.com/app/id1033007818", (long)_score];
NSArray *objectsToShare = @[text];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = @[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
}
iPhone代码(确实有效)
- (IBAction)ShareIt {
NSString * text = [NSString stringWithFormat:@"I just scored %li in Flying Freddy. Think you can beat it? https://itunes.apple.com/app/id1033007818", (long)_score];
NSArray * activityItems = @[text];
UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
avc.excludedActivityTypes = @[ UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:avc animated:YES completion:nil];
}
答案 0 :(得分:3)
您必须添加源视图。
尝试添加此行:
var lineByLine = require('n-readlines');
var liner = new lineByLine('./textFile.txt');
var line;
var lineNumber = 0;
while (line = liner.next()) {
console.log('Line ' + lineNumber + ': ' + line.toString('ascii'));
lineNumber++;
}
console.log('end of line reached');
您还可以添加箭头方向:
activityVC.popoverPresentationController.sourceView = self.view;
答案 1 :(得分:0)
我还必须为pipiks答案设置modalPresentationStyle,preferredContentSize和sourceRect。