我創建了一個UIButton
編程自定義UITableViewCell
內的UIButtons
細胞內部編號是動態的,起初它看起來完美的工作,但是當我打開所有的摺疊單元和滾動表視圖UIButton
彼此重疊,如果我滾動更多的屏幕之外的視圖中的UIButton
成爲隱藏,當你回到屏幕區域這裏是它的形象。UIButton的重疊和意外隱藏在裏面的UITableViewCell
我不是在這裏張貼的代碼,因爲它的大,我不知道哪一部分,我應該包括在這裏。如果被問到,我會在這裏發佈特定的代碼。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
InterestTableViewCell *cell = (InterestTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *category= (NSString *)[self.itemsInTable objectAtIndex:indexPath.row];
NSMutableArray *subcat =[[NSMutableArray alloc] init];
NSArray *keys = [cat allKeys];
id aKey = [keys objectAtIndex:indexPath.row];
subcat = [cat objectForKey:aKey];
cell.btnGroupTap.tag = indexPath.row+10000;
NSArray *count=(NSArray *)subcat;
int xoffset;
int yoffset = 0;
for(int i=0; i<count.count;i++)
{
if(i==0)
{
xoffset=0;
}
else
{
if(i%2 == 0)
{
xoffset = 0;
}
else
{
xoffset = 150;
}
}
if(i==0)
{
yoffset = 0;
}
else
{
if(i%2==0)
{
yoffset = yoffset+45;
}
}
NSString *sel = subcat[i][@"selected"];
NSString *key =subcat[i][@"key"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image;
if(![sel boolValue])
{
image = [UIImage imageNamed: @"unchecked.png"];
}
else
{
image = [UIImage imageNamed: @"checked.png"];
}
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(29,18,20,20)];
[imageView setImage:image];
UILabel *lbl1 = [[UILabel alloc] init];
[lbl1 setFrame:CGRectMake(0,5,100,20)];
lbl1.backgroundColor=[UIColor clearColor];
lbl1.textColor=[UIColor blackColor];
lbl1.frame = CGRectMake(40,0,100,40);
lbl1.numberOfLines =0;
[lbl1 setFont:[UIFont fontWithName:@"Roboto-Light" size:12]];
lbl1.text= subcat[i][@"value"];
button.tag= [key integerValue];
[button setTitle:@"" forState:UIControlStateNormal];
button.imageView.contentMode = UIViewContentModeScaleAspectFit;
[button setBackgroundImage:image forState:normal];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
button.frame = CGRectMake(xoffset,20+yoffset,(screenWidth/2)-40,40);
[button addTarget:self action:@selector(CheckAction:) forControlEvents:UIControlEventTouchUpInside];
[button addSubview:lbl1];
[cell.ContainerView addSubview:button];
[cell.ContainerView bringSubviewToFront:button];
}
cell.ContainerView.hidden=YES;
cell.lblCategory.text = category;
return cell;
}
注:我didSelectRowAtIndexPath
使用[tableView beginUpdates];[tableView endUpdates];
。
請分享代碼'cellForRowAtIndexpath'方法 –
請加'CheckAction:'事件代碼 –
CheckAction不需要,因爲我們是無論如何也稱它,但如果你想我將分享太 –