gpt4 book ai didi

iphone - iPhone 中的 GridView 问题

转载 作者:行者123 更新时间:2023-11-29 04:16:37 25 4
gpt4 key购买 nike

我正在 gridview 上显示图像。如果我有 4、8、12、16 等图像,它工作正常,但是当我的图像或多或少大于 4、8、12 时,我就无法单击它们。如果我有 6 个图像,那么我可以单击 4 个图像,但我无法单击第 5 个和第 6 个图像。

这是我的表格 View 代码

- (UITableViewCell *)tableView:(UITableView *)tableView_p cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *hlCellID = @"hlCellID";

UITableViewCell *hlcell = [tableView_p dequeueReusableCellWithIdentifier:hlCellID];
if(hlcell == nil) {
hlcell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:hlCellID] autorelease];
hlcell.accessoryType = UITableViewCellAccessoryNone;
hlcell.selectionStyle = UITableViewCellSelectionStyleNone;
}

int section = indexPath.section;
NSMutableArray *sectionItems = [sections objectAtIndex:section];

int n = [sectionItems count];
int i=0,i1=0;

while(i<n){
int yy = 4 +i1*74;
int j=0;
for(j=0; j<4;j++){

if (i>=n) break;
NSLog(@"Counter i %d , j %d , n %d ",i,j, n);
Item *item = [sectionItems objectAtIndex:i];

CGRect rect = CGRectMake(16+75*j, yy, 65, 65);
UIButton *button=[[UIButton alloc] initWithFrame:rect];
[button setFrame:rect];
//UIImage *buttonImageNormal=[UIImage imageNamed:item.image];
UIImage *buttonImageNormal = item.savedImage;
[button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
[button setContentMode:UIViewContentModeCenter];

NSString *tagValue = [NSString stringWithFormat:@"%d%d", indexPath.section+1, i];
button.tag = [tagValue intValue];
//NSLog(@"....tag....%d", button.tag);

[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[hlcell.contentView addSubview:button];
[button release];

/*UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake((75*j)-4, yy+44, 80, 12)] autorelease];
label.text = item.title;
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.font = [UIFont fontWithName:@"ArialMT" size:12];
[hlcell.contentView addSubview:label];
*/
i++;
}
i1 = i1+1;
}
return hlcell;
}

enter image description here

- (void)loadView {

[super loadView];
sections = [[NSMutableArray alloc] init];
imagesPath = [[NSMutableArray alloc] init];

for(int s=0;s<1;s++) { // 4 sections
sectionPattern = [[NSMutableArray alloc] init];


for(int i=0;i<9+3;i++) { // 12 items in each section
NSLog(@"Loop First %d",i);
//Here i am allocating images to sectionPattern and than in sections and using it later in above code
NSLog(@"Loop OUt %d",i);
}
[sections addObject:sectionPattern];

}
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}

最佳答案

如果没有更多代码,就很难说,但是您应该确保在 - (NSInteger)numberOfRowsInSection:(NSInteger)section 中返回正确的值

关于iphone - iPhone 中的 GridView 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13612870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com