MacDev 板


LINE

哈囉大家好,近來開始自學Objective-C on iOS Programming 參考書籍是 Learning iOS Programming 2nd / O'Reilly 目前嘗是撰寫一個讀取並分析RSS/xml的功能,參照書中作法建議一獨立Class (NSObject) 專責網路連線(NSURLConnection)與分析作業(libxml) 我在SPNewsGather中宣告四個 NSMutableArray 作為分析後資料儲存之用: 並建立一個溝通用的Method @property (weak, nonatomic) NSArray *titles; @property (weak, nonatomic) NSMutableArray *links; @property (weak, nonatomic) NSMutableArray *descriptions; @property (weak, nonatomic) NSMutableArray *images; - (void)rssGetter:(UIViewController *)controller; 而我的主體ViewController是tabbed table view 我先在SPAppDelegate 將SPNewsGather alloc/init 並 bind on viewControll: UIViewController *viewController1 = [[SPFirstViewController alloc] initWithNibName:@"SPFirstViewController" bundle:nil]; SPSecondViewController *viewController2 = [[SPSecondViewController alloc] initWithNibName:@"SPSecondViewController" bundle:nil]; UIViewController *viewController3 = [[SPThirdViewController alloc] initWithNibName:@"SPThirdViewController" bundle:nil]; UIViewController *viewController4 = [[SPFourthViewController alloc] initWithNibName:@"SPFourthViewController" bundle:nil]; UIViewController *viewController5 = [[SPFifthViewController alloc] initWithNibName:@"SPFifthViewController" bundle:nil]; SPNewsGather *newsGather = [[SPNewsGather alloc] init]; viewController2.newsGather = newsGather; self.tabBarController = [[UITabBarController alloc] init]; self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3, viewController4, viewController5]; self.window.rootViewController = self.tabBarController; 於SPSecondViewController 中也有 import & property: #import "SPNewsGather.h" @property (strong, nonatomic) SPNewsGather *newsGather; 在其implement也可以正確抓到 self.newsGather (type: SPNewsGather Object) 也可以正確執行Method: [self.newsGather rssGetter:self]; 在落落長的前提下,問題來了 在不斷插入中斷點,我確定rssGather:有執行,其中所有的NSMutableArray也都可以 在SPNewsGather中看到值,最後也透過 [viewController.tableView reloadData]; 來確保不會遇到不同資料問題,但是不管在reloadData之前或之後 SPSecondViewController中使用NSLog查看 self.newsGather.titles 的值都是(null) 本來我以為是連結上有問題,我有另外以同樣方法宣告一個 NSString *testString; 然後在SPnewsGather中改變他的值 然後我在SPSecondViewController 中 self.newsGather.testString 就可以看到正確的改變,也就是說只有NSMutableArray無法正確傳值 昨天測這個整夜沒睡,希望有高手可以幫個忙QQ 完整的程式碼可以在Github看到 https://github.com/fantasywind/Shockpaper 謝謝你花了時間看這篇落落長的問題 :) --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.45.22.35
1F:→ kiii210:build不起來..囧 08/09 20:50
2F:推 offname:有什麼特別的原因要用 weak 嗎? 08/09 20:55
3F:→ Fantasywind:書上的Parser例子只有用weak我就沒有特別想過 @@ 08/09 21:04
4F:→ Fantasywind:真的是這個問題!! 改成strong全部都正常了.. 08/09 21:06
5F:→ Fantasywind:來研究一下這部分 感謝offname大 !! 08/09 21:06
6F:→ Fantasywind:對ARC的運作實在不是很懂 08/09 21:08
7F:→ darktt:其實對ARC還不懂的話可以先關閉它,使用舊方法來解決即可 08/09 22:00







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Tech_Job站內搜尋

TOP