[問題] UITableView及Cell的問題(已解)

看板MacDev作者 (希當普利斯)時間9年前 (2016/02/15 15:06), 9年前編輯推噓2(206)
留言8則, 3人參與, 最新討論串1/1
最近小弟在學習 Objective-C 遇上了一些小問題 已經在 MainStoryBoard 新增兩個 Cell (姑且把ID設定為 cellOne 及 cellTwo) 然後在 numberOfRowsInSection 中設定第一個 section return 4 這樣第一個 section 就會跑 4 次 cell 到這邊的理解應該正確吧 ? 想問的是能夠上面兩個 row 使用 cellOne 下面兩個 row 使用 cellTwo 嗎 ? 還是一個 section 只能使用一種 cell 呢 ? 煩請各位解答了 m(_ _)m -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.70.195.104 ※ 文章網址: https://www.ptt.cc/bbs/MacDev/M.1455519975.A.EC9.html

02/15 15:26, , 1F
yes, you can do it.
02/15 15:26, 1F

02/15 16:39, , 2F
建立兩個cell class?
02/15 16:39, 2F

02/15 16:42, , 3F
然後在data source的cellForItemAtIndexPath
02/15 16:42, 3F

02/15 16:42, , 4F
加上if let cell as? cellTwo{}
02/15 16:42, 4F

02/15 16:42, , 5F
這樣吧
02/15 16:42, 5F

02/15 16:43, , 6F
阿 我是用swift 你在看看@@
02/15 16:43, 6F

02/15 18:25, , 7F
在cellForRowAtIndexPath判斷條件 return 不同的 cell
02/15 18:25, 7F

02/15 18:28, , 8F
你舉的例子大概就是 if (indexPath.row <=1) ... else ...
02/15 18:28, 8F
感謝各位,問題已經順利解決了 後來用 UITableViewCell *cell; if (indexPath.section == 1 && (indexPath.row == 0 || indexPath.row == 1)) cell = [tableView dequeueReusableCellWithIndentifier:@"cellOne"]; else cell = [tableView dequeueReusableCellWithIndentifier:@"cellTwo"]; 來處理 ※ 編輯: satou20444 (203.70.195.104), 02/16/2016 08:25:08
文章代碼(AID): #1MmNZdx9 (MacDev)
文章代碼(AID): #1MmNZdx9 (MacDev)