我正在创建一个iPhone应用程序。在那里我在表格单元格中显示一些内容。现在,我想在单击表格单元格时显示全尺寸图像。 我使用了以下代码。但是当我选择表格单元格时,我不知道如何以全屏显示图像。 而且当我在全屏显示图像时点击背景时我也想回来。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
const char *dbpath = [_databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &_beaconDB) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:
@"SELECT vendor_name, enter_message, enter_image, received_date, time_interval FROM beacons WHERE id=%@", [unique objectAtIndex:indexPath.row]];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(_beaconDB,
query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
title = [[NSString alloc]
initWithUTF8String:
(const char *) sqlite3_column_text(
statement, 0)];
description = [[NSString alloc]
initWithUTF8String:(const char *)
sqlite3_column_text(statement, 1)];
fullImg = [[NSString alloc]
initWithUTF8String:(const char *)
sqlite3_column_text(statement, 2)];
NSString *receivedDate = [[NSString alloc]
initWithUTF8String:(const char *)
sqlite3_column_text(statement, 3)];
NSString *timeInterval = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 4)];
BeaconAdTime *beaconAdTime = [[BeaconAdTime alloc] init];
NSDate *updatedTime = [beaconAdTime updatedDateTime:receivedDate andInterval:[timeInterval intValue]];
while (updatedTime!=nil)
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"MMM-dd hh:mm a"];
BeaconAdTime *beaconAdTime = [[BeaconAdTime alloc] init];
NSString *presentDateTime = [beaconAdTime presentDateTime];
NSDate *presentDateConvert = [dateFormatter dateFromString:presentDateTime];
if(updatedTime <= presentDateConvert)
{
// [message insertObject:description atIndex:indexPath.row];
// [vendor insertObject:title atIndex:indexPath.row];
cell.title.text = title;
cell.description.text = description;
cell.receivedDate.text = receivedDate;
break;
}
}
}
sqlite3_finalize(statement);
}
sqlite3_close(_beaconDB);
}
cell.title.text = vendor[indexPath.row];
cell.vendorImage.image = [UIImage imageNamed:@"gg.jpg"];
// cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:thumbnailImg]]];
return cell;
}
答案 0 :(得分:3)
类似的东西:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = tableView.visibleCells[indexPath.row];
UIViewController *imageVC = [UIViewController new];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
imageVC.view.frame = CGRectMake(0, 0, screenWidth, screenHeight);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageVC.view.frame];
imageView.image = cell.imageView.image;
imageView.userInteractionEnabled=YES;
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTouched:)];
[imageView addGestureRecognizer:tapGR];
[self presentViewController:imageVC animated:YES completion:nil];
}
如果您需要解释和/或进一步的帮助,请告诉我
答案 1 :(得分:0)
我认为您正在寻找的是深入研究表界面。
以下是Ray Wenderlich的一个例子:http://www.raywenderlich.com/913/sqlite-tutorial-for-ios-making-our-app。另外,这是Apple的官方参考:https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/TableViewAndDataModel/TableViewAndDataModel.html。
祝你好运!