Re: [問題] 呼叫新的view問題

看板MacDev作者 (阿翔)時間13年前 (2012/05/15 17:27), 編輯推噓3(307)
留言10則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《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
謝謝J大,抱歉可否給我一點delegate的作法參考
05/15 17:43, 1F

05/15 17:44, , 2F
老實說我還不太懂delegate的作法該怎麼寫
05/15 17:44, 2F

05/15 17:44, , 3F
美服真的是哭哭...
05/15 17:44, 3F

05/15 17:55, , 4F
所以你是用他的example?還是用你自己的project
05/15 17:55, 4F

05/15 17:56, , 5F
我把的class加到我的project裡了
05/15 17:56, 5F

05/15 17:57, , 6F
然後我的optestViewController一直都是on screen的狀態喔
05/15 17:57, 6F

05/15 18:00, , 7F
所以是已經有optestViewController了又再alloc一次?
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
謝謝j大,我想問如果我是用在CustomCell裡面的label呢...
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
j大,我試了幾天,我還是不太知道該怎麼實作
05/23 17:54, 9F

05/23 17:54, , 10F
對不起可以在給我一點提示嗎... ,謝謝
05/23 17:54, 10F
文章代碼(AID): #1FiY61RN (MacDev)
討論串 (同標題文章)
文章代碼(AID): #1FiY61RN (MacDev)