Re: [問題] UITableView動態增加資料

看板MacDev作者 (Johnny.T)時間12年前 (2013/05/23 00:59), 編輯推噓3(3010)
留言13則, 4人參與, 最新討論串2/3 (看更多)
錯了, insertRowsAtIndexPaths:withRowAnimation: Inserts rows in the receiver at the locations identified by an array of index paths, with an option to animate the insertion. - (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation Parameters indexPaths --> An array of NSIndexPath objects each representing a row --> index and section index that together identify a row in the table view. 這個method是要讓你在指定的indexPath插入資料, indexPaths這個陣列應該要是 NSIndexPath的陣列, 你的dataArray應該是tableView的dataSource..., 先在source插入資料沒錯,但是下一步要做的是把 NSIndexPath 用 NSArray 封裝起來 int count = [dataArray count]; NSIndexPath indexPath = [NSIndexPath indexPathForRow:count-2 section:0] NSArray *array = [NSArray arrayWithObject:indexPath]; [tableView insertRowsAtIndexPaths:array withRowAnimation:blablabla]; 這樣的code即是在倒數第二個row插入你要的資料~ 以上是之前開發的經驗,有說錯還請板上各位糾正~~! ※ 引述《siriuschill (siriuschill)》之銘言: : 我想自定一個Button : 點擊下去後 : tableview會自動增加一行 : 上網找了好多資料 : 都是在navigation上點擊實現 : 有嘗試過寫到Button裡 : 還是不行 : [self.tableView reloadData] : 還是不能刷新 : 請問各位大大 : 我是不是漏了什麼動作呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.248.95.215

05/23 01:02, , 1F
正解
05/23 01:02, 1F

05/23 01:27, , 2F
我改成這樣它還是沒新增QQ http://ppt.cc/8_P0
05/23 01:27, 2F

05/23 11:56, , 3F
你還是把完整的code貼上來好了
05/23 11:56, 3F

05/23 12:51, , 4F
看來我寫的你沒看到..
05/23 12:51, 4F

05/23 12:55, , 5F
05/23 12:55, 5F

05/23 15:59, , 6F
yuanruo大大 我有把reloadData拿掉過 不過還是不行
05/23 15:59, 6F

05/23 19:55, , 7F
05/23 19:55, 7F

05/23 20:03, , 8F
我把你整段程式碼call過來 原因在你beginupdate寫錯地方
05/23 20:03, 8F

05/23 20:04, , 9F
執行insertRowAtIndexPaths 你不加begin end 和reloadData
05/23 20:04, 9F

05/23 20:04, , 10F
以你的例子 都去掉就ok了
05/23 20:04, 10F

05/23 20:05, , 11F
你要寫beginUpdate 要寫在insert上面 完了後再endUpdate
05/23 20:05, 11F

05/23 22:15, , 12F
非常感謝yuanruo大大,把那2行拿掉後就解決了(^o^)
05/23 22:15, 12F

05/31 08:47, , 13F
竟然被m了....@@
05/31 08:47, 13F
文章代碼(AID): #1HdFcFQy (MacDev)
討論串 (同標題文章)
文章代碼(AID): #1HdFcFQy (MacDev)