iphone - iPhone 中的 GridView 问题

标签 iphone objective-c ios xcode

我正在 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/

相关文章:

iphone - 如何知道应用程序是否已预先安装在 iOS 设备上?

iphone - 如何创建逻辑彩色图

ios - 在沙盒模式下检查应用内购买自动续订订阅

iphone - AFJSONRequestOperation 数组填充但不能成功 block 之外的 NSLog 内容

iphone NSDate 转换问题

ios - 通知 iVar 值变化

iphone - RestKit 请求似乎只工作一次

ios - 需要在 UIActivitycontroller 中显示腾讯微博图标

iphone - 应用程序在同一行的第二次选择时崩溃

iphone - 轴标签也随图表一起滚动 : how to disable?