私はそれにカスタムビューを持つUITableViewを持っています。 tableviewの一番下には、そこに "Load More"セルを追加します。 クリック後、tableviewはより多くのデータを正常にロードし、 "Load More"セルはテーブルビューの一番下に残ります。 しかし、最初の "Load More"をクリックすると、2番目の "Load More"が表示され、2番目の "Load More"の同じセルにカスタム表示が残ります。 「詳細を読み込む」とカスタム表示が同じセルにあります。私はそのセルが "もっと見る"としか見えないようにしたい。UITableViewカスタムビューと同じセルに「詳細を読み込む」
この問題は、3番目の「4番目の負荷」に存在します。 誰でも助けてくれますか?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return imageCurPos+1;
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([aTableView tag]==501){
// Main Table
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
[[cell viewWithTag:3007] removeFromSuperview];
const NSInteger BOTTOM_LABEL_TAG = 3002;
UIImageView *bottomLabel;
UILabel *loadMore;
if(indexPath.row < imageCurPos){
if (cell == nil)
{ //All repeat things come here, if don't want to repeat here, please state outside this brucket
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//Edited
for (UIView *view in [cell.contentView subviews])
{
[view removeFromSuperview];
}
bottomLabel = [[[UIImageView alloc] initWithFrame: CGRectMake(50, 30, 250, 112)] autorelease];
[cell.contentView addSubview:bottomLabel];
bottomLabel.tag = BOTTOM_LABEL_TAG;
cell.backgroundView =
[[[UIImageView alloc] init] autorelease];
cell.selectedBackgroundView =
[[[UIImageView alloc] init] autorelease];
UIImageView *iconView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 30, 45, 45)] autorelease];
iconView.image = [UIImage imageNamed:@"02_bubble.png"];
[[cell contentView] addSubview:iconView];
bottomLabel.image = [UIImage imageNamed:@"05_bubble.png"];
}else if(indexPath.row == imageCurPos){ //For Load More
if (cell == nil)
{ //All repeat things come here, if don't want to repeat here, please state outside this brucket
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//Edited
for (UIView *view in [cell.contentView subviews])
{
[view removeFromSuperview];
}
loadMore =
[[[UILabel alloc]
initWithFrame:
CGRectMake(0, 0, 300, 50)]
autorelease];
loadMore.text = @"Load more...";
loadMore.textAlignment = UITextAlignmentCenter;
loadMore.tag = 3007;
loadMore.textColor = [UIColor whiteColor];
loadMore.backgroundColor = [UIColor darkTextColor];
[cell.contentView addSubview:loadMore];
}
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath{
if([tableView tag]==501){
if([indexPath row] != imageCurPos){
}else{ // For load more
NSLog(@"noRow Prev: %d", imageCurPos);
imageCurPos += interval;
NSLog(@"noRow After: %d", imageCurPos);
[tbl_mo_main reloadData];
}
}
ありがとう、私はこれを試しましたが、それは私にEXC_BAD_ACCESSエラーを与えました。 私はこれに2日間苦労しました。 –
変更したコードを更新し、メソッドパスの開始時にNSLogを実行してインデックスパスがクラッシュしていないか確認してください – Shubhank
if(cell == nil)の下にコードを追加しました。その他、質問で更新されました([cell.contentViewサブビューのUIView *ビュー]) ) {[view removeFromSuperview]; } –