在第13行之后无法加载UITableView行。数据再次从0重新加载。 我发现行已加载到13行。然后行将从头开始。
如果我将每行的高度设置为20.所有行都可以在一个屏幕中加载,然后一切都很好。
但是我需要将高度设置为40.然后就会出现问题。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"GroupsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
NSLog(@"test indexpath = %ld",(long)indexPath.row);
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
if(indexPath.row == 0){
UIImageView *profileImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 10, 80.0, 80.0)];
NSString *url = [[NSString alloc] init];
NSString *tempurl =self.iconimgpath;
NSLog(@"tempurl = %@",tempurl);
url = [NSString stringWithFormat:@"%@",tempurl];
NSURL * imageURL = [NSURL URLWithString:url];
profileImageView.contentMode = UIViewContentModeScaleAspectFit;
[profileImageView sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"loadinglogo.png"]];
profileImageView.tag = 11;
if([cell.contentView viewWithTag:11])
[[cell.contentView viewWithTag:11] removeFromSuperview];
[cell.contentView addSubview:profileImageView];
//[cell.contentView addSubview:profileImageView];
}
else{
if(_feedItems.count>0 && (indexPath.row > 0))
{
UILabel * groupnamelabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 15.0, 300,20)];
groupnamelabel.text = [_feedItems[indexPath.row-1] groupname];
//groupnamelabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:18];
groupnamelabel.tag = 99;
if([cell.contentView viewWithTag:99]){
[[cell.contentView viewWithTag:99] removeFromSuperview];
}
[groupnamelabel setFont:[UIFont systemFontOfSize:15]];
[cell.contentView addSubview:groupnamelabel];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushAction:)];
[groupnamelabel addGestureRecognizer:tap];
groupnamelabel.userInteractionEnabled = YES;
}
}
return cell;
我发现问题是
self.MyGrouptableview = [[UITableView alloc] initWithFrame:CGRectMake(0,65,screenWidth,screenHeight-150) style:UITableViewStylePlain];
如果我将tableview的高度设置得足够长,一切都会好的,但用户无法滚动到底部。