2013-03-04 64 views
0

我有一個tableview其中的單元格使用right detail layout。我現在想要做的是當用戶選擇一個單元格時。我應該添加一個圖像到那個單元格?更改所選的UITableViewCell佈局

任何建議我應該如何實施?

親切的問候

+0

你能不能請發佈代碼 – Kasaname 2013-03-04 11:02:25

+0

創建委託方法,並在單擊單元格時調用該方法 – Rushabh 2013-03-04 11:05:38

回答

1

爲此,您可以在-tableView:didSelectForRowAtIndexPath:即當用戶選擇,你可以創建一個圖像視圖,並將其添加

0

你還沒有給出關於您的圖片保留的任何細節。

如果您的圖片在緩存目錄,那麼你應該寫你-didSelectRowAtIndexPath這樣的...

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[[paths lastObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"Image-%d.png",indexPath.row]]]; 
yourImageView = [[UIImageView alloc] initWithImage:image]; 
[cell addSubView;yourImageView]; 

如果從服務器下載圖片,那麼你的代碼應該是這樣的:

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://yourURL.com"]]]; 
UIImage *image = [[UIImage alloc] initWithData:data]; 
yourImageView = [[UIImageView alloc] initWithImage:image]; 
[cell addSubView;yourImageView]; 

好運...!

0

嘗試實施這一

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.imageView.image = [UIImage imageNamed:@"imageName"]; 
} 
0

你可以創建你的UITableViewCell的子類。 然後實現方法-touchBegin,並且你需要