(首先,我是开发新手)我正在玩一个Treehouse Learning演示代码和我昨晚在互联网上找到的scrolllingTableView代码,并且能够将两个代码集成在一起,让一切正常工作。然后我错误地用我以前的版本保存了我的项目,并且无法让它重新恢复工作。我已经把它恢复到它接收来自Parse的消息,但没有以缩略图形式在scrollingTableView上显示它们,当我点击消息时我没有被带到detailViewController,就像我设置了我的segue一样。如果有人知道我这次出错的地方请给我一个抬头!干杯!
@interface AlbumsViewController ()<PPImageScrollingTableViewCellDelegate>
@property (strong, nonatomic) NSArray *images;
@end
@implementation AlbumsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Albums";
[self.tableView setBackgroundColor:[UIColor grayColor]];
self.moviePlayer = [[MPMoviePlayerController alloc] init];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
PFQuery *query = [PFQuery queryWithClassName:@"Messages"];
[query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]];
[query orderByDescending:@"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
else {
// We found messages!
self.messages = objects;
[self.tableView reloadData];
NSLog(@"Retrieved %d messages", [self.messages count]);
}
}];
}
pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.messages count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
PPImageScrollingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
PFObject *message = [self.messages objectAtIndex:indexPath.row];
cell.textLabel.text = [message objectForKey:@"senderName"];
NSString *fileType = [message objectForKey:@"fileType"];
if ([fileType isEqualToString:@"image"]) {
cell.imageView.image = [UIImage imageNamed:@"icon_image"];
NSLog(@"it's an image");
}
else {
cell.imageView.image = [UIImage imageNamed:@"icon_video"];
NSLog(@"it's a video");
}
return cell;
}
pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 150;
}
pragma mark - PPImageScrollingTableViewCellDelegate
- (void)scrollingTableViewCell:(PPImageScrollingTableViewCell *)scrollingTableViewCell didSelectImageAtIndexPath:(NSIndexPath*)indexPathOfImage atCategoryRowIndex:(NSInteger)categoryRowIndex
{
self.selectedMessage = [self.messages objectAtIndex:categoryRowIndex];
NSString *fileType = [self.selectedMessage objectForKey:@"fileType"];
if ([fileType isEqualToString:@"image"]) {
[self performSegueWithIdentifier:@"showDetail" sender:self];
}
else {
// File type is video
PFFile *videoFile = [self.selectedMessage objectForKey:@"file"];
NSURL *fileUrl = [NSURL URLWithString:videoFile.url];
self.moviePlayer.contentURL = fileUrl;
[self.moviePlayer prepareToPlay];
[self.moviePlayer thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame];
// Add it to the view controller so we can see it
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer setFullscreen:YES animated:YES];
}
[self.selectedMessage saveInBackground];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetail"]) {
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
DetailViewController *imageViewController = (DetailViewController *)segue.destinationViewController;
imageViewController.message = self.selectedMessage;
}
}
@end
答案 0 :(得分:0)
有关单元格选择的问题,您需要调用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PFObject *object = [images objectAtIndex:indexPath.row];
}