Re: [問題] 呼叫新的view問題
※ 引述《lazyasa (asa)》之銘言:
: Dear all
: 不知道今天問問題還有沒有人回.. XD
: 大家都D3去了..
: 小弟我最近想把在label出現的文字連結加上url link,
: 於是我用了OHAttributedLabel這個套件
: 套件本身點了連結會直接開啟safari
: 但我把它改成開啟TSMiniWebBrowser
: if (activeLink && (NSEqualRanges(activeLink.range,linkAtTouchesEnded.range) || closeToStart)) {
: BOOL openLink = (self.delegate && [self.delegate respondsToSelector:@selector(attributedLabel:shouldFollowLink:)])
: ? [self.delegate attributedLabel:self shouldFollowLink:activeLink] : YES;
: if (openLink) {
: NSString *url = [activeLink.URL absoluteString];
: optestViewController *viewcontroller = [[optestViewController alloc] init];
: [viewcontroller linkButtonPressed:url];
: [viewcontroller release];
: }
: }
: - (void) presentModalWebViewController:(BOOL) animated {
: // Create webViewController here.
: [self presentModalViewController:webViewController animated:animated];
: self.modalWebViewPresented = YES;
: }
: 的確是可以正常的NSlog出東西
: 但不知道為什麼不會正確呼叫出webViewController
: 有大大可以為我解惑一下嗎?
: 謝謝
問題在這個optestViewController 根本就沒有on screen
沒on screen 的 view controller 是沒有辦法 presentModalViewController的
比較好的做法是把開url這件事delegate出去給你在螢幕上的view controller。
ps:他的example 寫得有點鳥,完全沒有用到viewcontroller.也沒用到delegateXD.
ps2:暗黑美國帳號不知道要等到何年何月才能登亞服...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.128.223.100
推
05/15 17:43, , 1F
05/15 17:43, 1F
→
05/15 17:44, , 2F
05/15 17:44, 2F
→
05/15 17:44, , 3F
05/15 17:44, 3F
→
05/15 17:55, , 4F
05/15 17:55, 4F
→
05/15 17:56, , 5F
05/15 17:56, 5F
→
05/15 17:57, , 6F
05/15 17:57, 6F
→
05/15 18:00, , 7F
05/15 18:00, 7F
=====OHAttributedLabel.h
@protocol OHAttributedLabelDelegate <NSObject>
@optional
//add following line
-(void)openURL:(NSURL *)url;
======OHAttributedLabel.m
BOOL openLink = (self.delegate &&
[self.delegate
respondsToSelector:@selector(attributedLabel:shouldFollowLink:)])
? [self.delegate attributedLabel:self shouldFollowLink:activeLink] : YES;
if (openLink) [[UIApplication sharedApplication] openURL:activeLink.URL];
//change privious line to following
if (openLink&&[delegate respondsToSelector:@selector(openURL:)])
[delegate openURL:activeLink.URL]
=====optestViewController.m
加入下面的method
-(void)openURL:(NSURL*)url{
[self linkButtonPressed:url];
}
=====
我不知道你是用IB還是直接call 出label的
反正把
label.delegate = optestViewController;
用IB的話就連連看吧
應該就可以work了
※ 編輯: johnlinvc 來自: 220.128.223.100 (05/15 18:18)
推
05/16 15:04, , 8F
05/16 15:04, 8F
那就作一個UITableViewCell的Subclass,把delegate設成cell,
再讓cell去呼叫viewcontroller 的linkButtonPressed
※ 編輯: johnlinvc 來自: 220.128.223.100 (05/16 15:46)
推
05/23 17:54, , 9F
05/23 17:54, 9F
→
05/23 17:54, , 10F
05/23 17:54, 10F
討論串 (同標題文章)