作者tref (MFDA)
看板MacDev
標題[問題] Custom Cell的幾個問題
時間Tue May 15 08:19:21 2012
各位大大,小弟想請教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
推 appleway:U doesn't reuse the labels you add to cells 05/15 09:20
→ tref:有試過將addSubView加到cell==nil的迴圈外,但會造成Label重 05/15 09:52
→ tref:疊,原本的Label並不會清除,請問有什麼方法嗎?謝謝 05/15 09:54
推 ChonPiggy:第一個問題是用 reload 還是 loadview 解決..有點忘了 05/15 10:27
→ ChonPiggy:阿..reloadData ? 05/15 10:28
→ ChonPiggy:應該在 didSelect 裡面也要 reload 一次吧 上面沒這段 05/15 10:29
推 iwayne:連結tableView的MutableArray你有處理了,但tableView也要 05/15 12:56
→ iwayne:reload..如果你不想reload,也可以直接call tableview的函 05/15 12:57
→ iwayne:式,把tableview某個item刪掉。(這樣是比較有效率的,但前 05/15 12:57
→ iwayne:提是item不要太多,不然reload是比較快的。 05/15 12:58
→ tref:已解決,謝謝各位 05/15 13:24