我正在尝试实现用Swift编写的代码,看看它是否能够在我已经制作的Objective-C项目中实现我想要的内容,但是我在尝试翻译/重新翻译时遇到了麻烦它到Objective-C。
以下是swift中的代码:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var feedContent:String! = "<h3>\(selectedFeedTitle)</h3>\(selectedFeedContent)"
myWebView.loadHTMLString(feedContent, baseURL: nil)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "openWebPage" {
let fwpvc: FeedWebPageViewController = segue.destinationViewController as! FeedWebPageViewController
selectedFeedURL = selectedFeedURL.stringByReplacingOccurrencesOfString(" ", withString:"")
selectedFeedURL = selectedFeedURL.stringByReplacingOccurrencesOfString("\n", withString:"")
fwpvc.feedURL = selectedFeedURL
}
}
我已将override func
更改为-(void)
,将super.viewDidLoad()
更改为[super viewDidLoad];
,并且它已接受但没有错误,但它给了我错误该代码中还有几行。我在网上寻找翻译技巧,但仍无法让他们工作。
答案 0 :(得分:2)
它应该转换为类似的东西(未在实际的IDE中测试):
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *feedContent = [NSString stringWithFormat:@"<h3>%@\</h3>%@", selectedFeedTitle, selectedFeedContent];
[myWebView loadHTMLString:feedContent baseURL:nil];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"openWebPage"]) {
FeedWebPageViewController *fwpvc = (FeedWebPageViewController *)segue.destinationViewController;
selectedFeedURL = [selectedFeedURL stringByReplacingOccurrencesOfString:@" " withString:@""];
selectedFeedURL = [selectedFeedURL stringByReplacingOccurrencesOfString:@"\n" withString:@""];
fwpvc.feedURL = selectedFeedURL;
}
}