嘿,我从RSS中获得了大量图像我必须将所有图像显示为专辑,而我不知道所有专辑中的热门设置......
我认为使用Table View制作自定义相册是正确的方法但我有点困惑,而不是如何从一行中正确点击特定图像...
在我的自定义单元格中我放了三个imageView ...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
appDeleg = (NewAshley_MedisonAppDelegate *)[[UIApplication sharedApplication] delegate];
static NSString *CellIdentifier = @"Cell";
MyCustomCell *cell = (MyCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"MyCustomCell"
owner:self options:nil];
cell = mycustomcell;
self.mycustomcell = nil;
}
int index = indexPath.row;
imageData *objImage = [appDeleg.downloadImageData objectAtIndex:index];
[[cell imgView1] setImage:objImage.image1];
imageData *objImage = [appDeleg.downloadImageData objectAtIndex:index + 1];
[[cell imgView2] setImage:objImage.image2];
imageData *objImage = [appDeleg.downloadImageData objectAtIndex:index + 2];
[[cell imgView3] setImage:objImage.image3];
return cell;
}
//在Next循环中我得到索引1所以为此我找到方法添加每个时间序列像1,3,5,7 ...所以我得到但我不知道如何设置(如何在目标C)中执行此逻辑
答案 0 :(得分:1)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
// CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
ImageData * objImage1 = [[ImageData alloc] init];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
int n = indexPath.row * 2;
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1 = [[UIButton alloc] initWithFrame:CGRectMake(11.0f, 0.0f,145.0f, 100.0f)];
objImage1 = [appDelg.imageArray objectAtIndex:n];
[button1 setImage:objImage1.imgData forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button1];
if(n+1 < [appDelg.imageArray count]){
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
objImage1 = [appDelg.imageArray objectAtIndex:n+1];
button2 = [[UIButton alloc] initWithFrame:CGRectMake(162.0f, 0.0f,145.0f, 100.0f)];
[button2 setImage:objImage1.imgData forState:UIControlStateNormal];
//[button1 setTitle:@"Do Stuff" forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button2];
}
else {
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2 = [[UIButton alloc] initWithFrame:CGRectMake(162.0f, 0.0f,145.0f, 100.0f)];
[button2 setImage:[UIImage imageNamed:@"white.png"] forState:UIControlStateNormal];
[button2 setEnabled:YES];
[button2 setSelected:NO];
button2.alpha = 1.0;
[cell addSubview:button3];
}
return cell;
}
我的两种图像方法......
- (void)buttonPressedAction:(id)sender
{
button1 = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell*)[button superview];
int row = [tblView indexPathForCell:cell].row;
int n = row * 2;
NSLog(@"Button Pressed %d", n);
NSString *str = [NSString stringWithFormat:@"%d",n+1];
objImage = [[ShowImage alloc] initWithNibName:@"ShowImage" bundle:nil];
[objImage imageSelect:n :str];
[self.view.window addSubview:objImage.view];
}
我尝试使用UIIMage视图,但在这种情况下我不会在我的Tap操作中获得按钮ID ....
button2 = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell*)[button2 superview];
int row = [tblView indexPathForCell:cell].row;
我的应用程序崩溃上面代码的第二行.....
但按钮应用程序没有问题顺利......