2013-07-04 15 views
0

我的tableView與指示燈,但是當我在按鈕點擊顯示SMaL公司popwindow形象我想,圖像應該與細胞排列如果單擊的單元格位於頂部,然後彈出窗口應顯示在頂部如果細胞clciked是middel那麼根據。如何的圖片瀏覽位置設置的UITableViewCell的中心在iPhone

現在我有一個在固定的位置在屏幕上。

我要讓像正常的iPad應用程序,當你按下然後任意單元格按鈕,彈出addtoFave的按鈕與該小區神韻:任何想法如何完成這件事。

這裏是我當前的代碼:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSLog(@"ContentID %@",contentID); 

    CustomCell *cell = (CustomCell *) [tblSimpleTable cellForRowAtIndexPath:indexPath]; 

    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 312, 105)]; 
    imgView.frame = CGRectMake((cell.frame.size.width/2)-(imgView.frame.size.width/2), (cell.frame.size.height/2)-(imgView.frame.size.height/2), 312, 105); 

    imgView.image=[UIImage imageNamed:@"popupj.png"]; 

    [cell addSubview:imgView]; 

} 

但是這顯示了在小區中的一個並非所有圖像時,我當我在其他小區點擊此圖片顯示在第一個單元格單擊僅我想,哪個單元選擇這應該顯示給那個單元格。

+0

你的問題不明確。放一些代碼或更多的信息,這將幫助你。 –

+0

你想顯示彈出窗口,你點擊單元格,是這樣嗎? – Mital

+0

@Mital你是對的我想這樣,因爲你要求 –

回答

5

首先加入這一行myImageView.center = cell.center;並將其添加到cell.contentViewmyImageView

OR

你也可以把用於顯示圖像的代碼中的UITableViewCell中心。

myImageView.center = CGPointMake(cell.contentView.bounds.size.width/2,cell.contentView.bounds.size.height/2); 
+0

這不起作用細胞 –

1

//如果你想顯示在中心內的任何視圖中的任意子視圖..試試這個..從選擇選項1以下

//選項1:

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; 
    imgView.frame = CGRectMake((cell.frame.size.width/2)-(imgView.frame.size.width/2), (cell.frame.size.height/2)-(imgView.frame.size.height/2), 50, 50); 
    [cell addSubview:imgView]; 

//選項2:

//在.H

int selectedRow; 

//在.M

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.row == selectedRow) 
    { 
     UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; 
     imgView.frame = CGRectMake((cell.frame.size.width/2)-(imgView.frame.size.width/2), (cell.frame.size.height/2)-(imgView.frame.size.height/2), 50, 50); 
     imgView.image = [UIImage imageNamed:@"Select.png"]; 
     [cell addSubview:imgView]; 
     [imgView release]; 
     imgView = nil; 
    } 
    else 
    { 
     UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; 
     imgView.frame = CGRectMake((cell.frame.size.width/2)-(imgView.frame.size.width/2), (cell.frame.size.height/2)-(imgView.frame.size.height/2), 50, 50); 
     imgView.image = [UIImage imageNamed:@"UnSelect.png"]; 
     [cell addSubview:imgView]; 
     [imgView release]; 
     imgView = nil; 

    } 
} 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    selectedRow = indexPath.row; 
    [tableview reloadData]; 
} 
+0

上面顯示的圖像,它只是顯示一個小區當我點擊我寫這段代碼在做選擇,所以當電池選擇顯示此所選單元格 –

+0

不要寫在didselect這個代碼,因爲如果你移動表格向上或向下選擇部分將刷新(意味着你看不到選定的行).so,在cellforrow中應用此代碼。但你需要在那裏應用一些邏輯 –

+0

如何做到這一點,如果我在cellForRow中寫入這樣它不會爲其他工作,所以有可能添加此圖像查看,而不是單元格在相同的位置,那麼它可能工作 –

1

這是我做了我的UIImageView使用自定義的UITableViewCell居中。

一定要在覆蓋添加此代碼FUNC layoutSubviews(){}您的UITableViewCell類的一部分。

var cellHeight:CGFloat = 150 
    self.imageLogo.frame = CGRectMake(0, 0, 125, 125) 
    self.imageLogo.center = CGPoint(x: self.center.x, y: cellHeight/2) 
    self.imageLogo.image = Common.school_crest_image 
    self.imageLogo.contentMode = UIViewContentMode.ScaleAspectFit 
    self.addSubview(self.imageLogo) 
相關問題