MacDev 板


LINE

我有個 .xib 檔,是要客製化 TableViewCell 的 Interface Builder 內的 File Owner 及 該 cell 都有設定為我的 custom class 然後我利用 table view的 registerNib:forCellReuseIdentifier: 來註冊一個 reuseID 及對應的 nib 問題出在 dataSource 的地方 我利用 table view 的 -dequeueReusableCellWithIdentifier: 來得到一個 cell table view 卻給我一個 UITableViewCell 而非我的 custom class 但是 cell 的 UI 介面,的確跟我 nib 檔內的設置是一樣的 但這樣我就沒有 customized cell 的功能了... 請問是我哪裡有弄做什麼? 還是 -dequeueReusableCellWithIdentifier: 的問題 只會回傳 UITableViewCell? --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.163.125.199
1F:推 kiii210:(yourCustomCell *)[tableview dequeueReuse....]; 08/01 19:25
2F:→ kiii210:yourCustomCell *cell = [tableview dequeueReusable...]; 08/01 19:26
這邊宣告回傳物件為某個型別 也無法改變該物件原本類別的事實... NSLog(@"cell class: %@", NSStringFromClass([cell class])); 會printt出"UITableViewCell"
3F:→ kiii210:= =我到底在打什麼 08/01 19:26
4F:→ kiii210:你有照我第二行打的那樣打嗎?你是要在哪裡用到cell? 08/01 19:27
5F:→ kiii210:cellForRowAtIndexPath? 08/01 19:28
6F:→ kiii210:你的cell要是你自己的Custom Cell的class才行唷 08/01 19:39
// data source - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ CustomizedCell *cell = [tableView dequeueReusableCellWithIdentifier:id]; NSLog(@"cell: %@", cell); // 此時cell會存在 而且的確是load Nib的UI // 但是class一直都是UITableViewCell; if (!cell){ NSLog(@"永遠不會進來,因為我已用registerNib:forCellReuseIdentifier:"); // 以前dequeue沒有cell的話 要在這邊手動自己create cell // 可以用 alloc-init 或是在這邊用 nib file 來創造 cell // 但實際上只要register該reuse identifer,dequere時一定有cell // UIKit會根據register的Nib或class 來產生該cell // 所以這邊if statement不會通過 其實這邊不用寫code // 只是好像-dequeueReusableCellWithIdentifier: 創造出來的cell // 都是UITableViewCell... (無論我Nib設file owner/cell的class 都無效) // 不知道真的是bug 還是我漏掉設定什麼? } return cell; } ※ 編輯: leondemon 來自: 114.198.184.235 (08/02 00:23)
7F:推 kiii210:這要等高手啦 XD 08/02 09:46
8F:→ kiii210:你的意思是,你的cell底下沒有你自己CustomCell的object? 08/02 09:47
9F:→ kiii210:等高手來之前 要不要把完整code丟上來看看 08/02 09:51
10F:→ hSATAC:http://pastebin.com/3uPySKQ8 試試? 08/02 10:32
後來我找到問題了 雖然不知道是怎麼回事 因為 Xcode 在 subclass UITableViewCell 時 沒有同時產生 xib檔的選項 所以必須自己手動加入一個 .xib 檔 而當初創造該 xib 檔時 從清單中選了empty的選項 才會發生此事 (想說也不是要customize UIView/UIWindow 直接從空白的開始設定) 後來重新建立 .xib 新檔時 選了 View 的 xib 選項 然後把該 view 給刪除掉之後 重新加入一個 table view cell 這樣在 register 之後 就會確實產生我設定的類別物件 只不過我還是不知道 empty 的 xib 檔是要拿來做什麼用的... 還是 empty 的 xib 檔還要設定什麼地方 才能拿來給 table view register? ※ 編輯: leondemon 來自: 118.163.125.199 (08/02 14:03)
11F:推 kiii210:你有連Files Owner的view outlet出去嗎? 08/02 15:23







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燈, 水草

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

TOP