【发布时间】:2011-06-22 06:29:22
【问题描述】:
在我的应用程序中,我有一个弹出式控制器,当从其他视图单击时,它会显示一堆图像。另一个视图中有一些图像。所有图像上方都有一个箭头按钮,点击该按钮会弹出显示。让我来看看问题。比如说,我单击第二张图像上方的箭头按钮并弹出显示。现在,当我从弹出窗口中选择任何图像时,我想将该图像设置为存在于主视图(或包含箭头按钮的图像视图)。但我得到的是,当我从弹出窗口中选择任何图像时,它总是被设置为主视图中存在的最后一个图像视图。我想设置它在上面的同一个图像视图上,其箭头按钮被单击以显示弹出窗口。
我的代码是:-
主视图:--
- (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];
}
请帮忙。是标签问题吗,请告诉我如何检查现在正在进行哪个标签,我可以通过它获得图像视图。请回答。
【问题讨论】:
-
@deepak-你能帮我解决这个问题吗
-
何时调用
showPopOver? -
在按钮动作点击中调用
-
如何设置
imageView?和按钮动作有关系吗?
标签: objective-c cocoa-touch ipad tags uiimageview