【发布时间】:2012-11-23 03:32:43
【问题描述】:
我正在构建一个使用 UICollectionView 来显示博客文章数组的应用程序。
当用户点击帖子时,会推送一个 DetailView 以显示帖子的内容。
在详细视图中,可以看到帖子图片、文字等。还有一个显示 cmets 的按钮。
我希望用户能够点击comments 按钮并加载一个UITableView,它将显示为该帖子编写的所有cmets。这是我无法实现的部分。
我使用界面生成器创建了一个 UITableView,并使用 segue 将其连接到 DetailView。当点击comments 按钮时,我得到一个空表。
在我的 DetailView 上,点击 cmets 按钮会触发:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showComments"]) {
NSDictionary *post = self.detailItem;
NSArray *commentThread = [post objectForKey:@"comment"];
// how do I pass the commentThread to the UITableView at the other end of the segue?
}
}
有任何想法如何完成这项工作吗?很高兴发布更多代码。
这是我的CommentViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"commentCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *comment = [self.commentArray objectAtIndex:indexPath.row];
NSString *commentText = [comment objectForKey:@"comment_text"];
NSString *commentAuthor = [comment objectForKey:@"comment_author"];
cell.textLabel.text = commentText;
return cell;
NSLog(@"%@", comment);
}
还有CommentViewController.h
#import <UIKit/UIKit.h>
@interface CommentViewController : UITableViewController {
NSArray *commentArray;
}
@property (strong, nonatomic) id commentArray;
@end
【问题讨论】:
标签: iphone objective-c ios uitableview ios5