在我的应用程序中,我有一个弹出控制器,当从其他视图点击时显示一堆图像。另一个视图中有一些图像。所有图像上方都有一个箭头按钮,点击弹出结果获取我转到了问题。例如,我点击了第二张图片上方的箭头按钮并弹出显示。现在当我从弹出窗口中选择任何图像时,我想将该图像设置为图像视图主视图(或由箭头按钮组成的图像视图)。但我得到的是,当我从弹出窗口中选择任何图像时,它总是被设置为主视图中出现的最后一个图像视图。我想设置它位于上方相同的图像视图上,其中单击了箭头按钮以显示弹出窗口。
我的代码是: -
主要观点: -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier] autorelease];
UIImageView * imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(25, 4, 80, 80)] autorelease];
UIImageView * imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake(115,4,80, 80)] autorelease];
UIImageView * imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake(205,4, 80, 80)] autorelease];
UIImageView * imageView4 = [[[UIImageView alloc] initWithFrame:CGRectMake(295,4, 80, 80)] autorelease];
imageView1.tag = j;
imageView2.tag = j+1;
imageView3.tag = j+2;
imageView4.tag = j+3;
[cell.contentView addSubview:imageView1];
[cell.contentView addSubview:imageView2];
[cell.contentView addSubview:imageView3];
[cell.contentView addSubview:imageView4];
}
for ( int i = 1; i <= j; i++ ) {
imageView = (UIImageView *)[cell.contentView viewWithTag:i];
imageView.image=nill
}
int photosInRow;
if ( (indexPath.row < [tableView numberOfRowsInSection:indexPath.section] - 1) || ([sentence count] % 4 == 0) ) {
photosInRow = 4;
} else {
photosInRow = [sentence count] % 4;
}
for ( int i = 1; i <=[sentence count]; i++ ){
imageView = (UIImageView *)[cell.contentView viewWithTag:i];
[self setImage1:imageView];
}
return cell;
}
点击按钮的事件: -
-(void)showPopOver:(id)sender
{
ModalView *mvc = [[ModalView alloc]init];
[mvc settingParentButton:imageView];
[mvc settingPop:detailViewPopover];
// Present the popover from the button that was tapped in the detail view.
[detailViewPopover presentPopoverFromRect:CGRectMake(0,0, 325, 650) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
// Set the last button tapped to the current button that was tapped.
[mvc release];
}
设置模态视图的父按钮事件: -
-(void)settingParentButton:(UIImageView *)imageView {
imageView1=imageView;
}
并在模态视图的索引路径上选择了行: -
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(imageView1.tag);
if (indexPath.row==0) {
[imageView1 setImage:[UIImage imageNamed:[nsmResult objectAtIndex:indexPath.row]] ];
}
if (indexPath.row==1) {
[imageView1 setImage:[UIImage imageNamed:[nsmResult objectAtIndex:indexPath.row]] ];
}
if (indexPath.row==2) {
[imageView1 setImage:[UIImage imageNamed:[nsmResult objectAtIndex:indexPath.row]] ];
}
if (indexPath.row==3) {
[imageView1 setImage:[UIImage imageNamed:[nsmResult objectAtIndex:indexPath.row]] ];
}
[pop2 dismissPopoverAnimated:YES];
}
请帮助。这是标签问题,请告诉我如何查看正在进行哪个标签,我可以通过该标签查看图片。请回答。
答案 0 :(得分:0)
在创建内存分配时,在该imageview中,不应该自动释放,在dealloc中释放你的记忆,你的预期图像将被放置在你的出现中。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *im = [info objectForKey:UIImagePickerControllerOriginalImage];
self.imageView.image = im;
UIImageWriteToSavedPhotosAlbum(im, nil, nil, nil);
imageView.contentMode = UIViewContentModeScaleAspectFit;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
@interface testpViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
IBOutlet UIImageView *imageView;
}
@property (nonatomic, retain) UIImageView *imageView;