我有一個tableview
其中的單元格使用right detail layout
。我現在想要做的是當用戶選擇一個單元格時。我應該添加一個圖像到那個單元格?更改所選的UITableViewCell佈局
任何建議我應該如何實施?
親切的問候
我有一個tableview
其中的單元格使用right detail layout
。我現在想要做的是當用戶選擇一個單元格時。我應該添加一個圖像到那個單元格?更改所選的UITableViewCell佈局
任何建議我應該如何實施?
親切的問候
爲此,您可以在-tableView:didSelectForRowAtIndexPath:
即當用戶選擇,你可以創建一個圖像視圖,並將其添加
你還沒有給出關於您的圖片保留的任何細節。
如果您的圖片在緩存目錄,那麼你應該寫你-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];
好運...!
嘗試實施這一
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.imageView.image = [UIImage imageNamed:@"imageName"];
}
你可以創建你的UITableViewCell的子類。 然後實現方法-touchBegin,並且你需要
你能不能請發佈代碼 – Kasaname 2013-03-04 11:02:25
創建委託方法,並在單擊單元格時調用該方法 – Rushabh 2013-03-04 11:05:38