我已经整天搜索了Google,但我无法找到解决方案.
我正在尝试在我的iOS应用程序中使用自定义单元格实现表格视图.我正在使用显示不同图像和标签的自定义单元格.一切都工作正常,除了单元格对于表格视图来说太大了.我知道我需要实现heightForRowAtIndexPath方法,但从不调用它.
我已经尝试在nib文件和代码中的ShowPostsViewController中设置TableView的委托,但没有任何帮助.我希望问题可能是dataSource已设置但不是委托.我无法理解为什么.
到目前为止我发现的每个解决方案都说代理设置不正确.但是,我很确定这是我的情况?!我很感激任何帮助.这是我的代码:
ShowPostsViewController.h
@interface ShowPostsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) IBOutlet UITableView *postsTableView;
@end
Run Code Online (Sandbox Code Playgroud)
和ShowPostsViewController.m
@implementation ShowPostsViewController
@synthesize postsTableView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.postsTableView.delegate = self;
self.postsTableView.dataSource = self;
NSLog(@"Delegate set");
[postsTableView beginUpdates];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
for(int i=0; i<8; i++){
[tempArray addObject: [NSIndexPath indexPathForRow:i inSection:0]];
}
[postsTableView insertRowsAtIndexPaths:tempArray withRowAnimation:UITableViewRowAnimationAutomatic];
NSLog(@"Updates Called");
[postsTableView endUpdates];
[postsTableView reloadData];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 8;
}
//PostTableViewCell is my custom Cell that I want to display …Run Code Online (Sandbox Code Playgroud)