[問題] Custom Cell的幾個問題

看板MacDev作者 (MFDA)時間13年前 (2012/05/15 08:19), 編輯推噓3(308)
留言11則, 4人參與, 最新討論串1/2 (看更多)
各位大大,小弟想請教2個問題: 1.當我 Custom Cell 時,但若到 DetailViewController 去修改Array的內容後 , 返回上一頁 Cell 顯示的卻還是修改之前的內容,有確認Array的內容無誤 aArray、bArray...等皆為NSMutableArray,請問到底是那裡出錯了?? 2.當Cell資料較多時,超出一個頁面所能呈現出的資料,EX:超過21筆 ,將畫面 上下捲動會出現其他資料沒錯,但資料的排序會亂掉,點選亂掉的資料進入 DetailViewController也與Cell所呈現的資料不相符 請問各位到底是什麼問題?找不出原因苦惱中..... 謝謝 Code如下: - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.tableView reloadData]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; //增加LABEL UILable *aLabel = [[UILabel alloc] initWithFrame:CGRectMake(105.0, 10, 125, 22.0)]; [aLabel setText:[NSString stringWithFormat:@"%@",[aArray objectAtIndex:indexPath.row]]]; UILable *bLabell = [[UILabel alloc] initWithFrame:CGRectMake(500.0,10.0, 125, 22.0)]; [bLabell setText:[NSString stringWithFormat:@"%@",[bArray objectAtIndex:indexPath.row]]]; UILable *cLabel = [[UILabel alloc] initWithFrame:CGRectMake(360.0, 10, 125, 22.0)]; [cLabel setText:[NSString stringWithFormat:@"%@",[cArray objectAtIndex:indexPath.row]]]; UILable *dLabel = [[UILabel alloc] initWithFrame:CGRectMake(230.0, 10, 125, 22.0)]; [dLabel setText:[NSString stringWithFormat:@"%@",[dArray objectAtIndex:indexPath.row]]]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; [[cell contentView]addSubview:aLabel]; [[cell contentView]addSubview:bLabell]; [[cell contentView]addSubview:cLabel]; [[cell contentView]addSubview:dLabel]; } return cell; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.241.181.12

05/15 09:20, , 1F
U doesn't reuse the labels you add to cells
05/15 09:20, 1F

05/15 09:52, , 2F
有試過將addSubView加到cell==nil的迴圈外,但會造成Label重
05/15 09:52, 2F

05/15 09:54, , 3F
疊,原本的Label並不會清除,請問有什麼方法嗎?謝謝
05/15 09:54, 3F

05/15 10:27, , 4F
第一個問題是用 reload 還是 loadview 解決..有點忘了
05/15 10:27, 4F

05/15 10:28, , 5F
阿..reloadData ?
05/15 10:28, 5F

05/15 10:29, , 6F
應該在 didSelect 裡面也要 reload 一次吧 上面沒這段
05/15 10:29, 6F

05/15 12:56, , 7F
連結tableView的MutableArray你有處理了,但tableView也要
05/15 12:56, 7F

05/15 12:57, , 8F
reload..如果你不想reload,也可以直接call tableview的函
05/15 12:57, 8F

05/15 12:57, , 9F
式,把tableview某個item刪掉。(這樣是比較有效率的,但前
05/15 12:57, 9F

05/15 12:58, , 10F
提是item不要太多,不然reload是比較快的。
05/15 12:58, 10F

05/15 13:24, , 11F
已解決,謝謝各位
05/15 13:24, 11F
文章代碼(AID): #1FiQ4Boo (MacDev)
文章代碼(AID): #1FiQ4Boo (MacDev)