【发布时间】:2017-04-10 05:59:37
【问题描述】:
在 UIView 类上添加 UIViewController 有 UITableView 类现在 UIView 类被添加到另一个 UIViewController 类
//MyControllerView
//added filterSideView side to it and adding JaffaViewController.view
-(void)loadControllerJaffa
{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
JaffaViewController *jaffaViewController =
[storyboard instantiateViewControllerWithIdentifier:@"JaffaViewController"];
jaffaViewController.view.frame = filterSideView.bounds;
[filterSideView addSubview:jaffaViewController.view];
[jaffaViewController didMoveToParentViewController:self];
}
#import <UIKit/UIKit.h>
@interface JaffaViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *jaffaTableView;
@end
实现类
@implementation JaffaViewController
- (void)viewDidLoad {
[super viewDidLoad];
_colorNameList = [[ColorModelClass colorListNames]allKeys];
_jaffaTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
_jaffaTableView.dataSource = self;
_jaffaTableView.delegate = self;
[_jaffaTableView setBackgroundColor:[UIColor redColor]];
// Do any additional setup after loading the view.
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
_jaffaTableView.dataSource = self;
_jaffaTableView.delegate = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; //count of section
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleTableCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"SimpleTableCell"];
}
cell.textLabel.text = @"Welcome";
return cell;
}
问题是cellForRowAtIndexPath 方法根本没有被调用。
我已经设置了数据源和委托方法。
它正在调用numberOfRowsInSection 和numberOfSectionsInTableView 两种方法,但不是cellForRowAtIndexPath 方法。
目前我正在使用 Xcode 8.3 和 iOS 10.3 版本。
您的善意意见将帮助我解决问题。
【问题讨论】:
-
如果 numberOfRows 或 Sections 为零。它不会撤销。检查 numberOfRows
-
确保委托方法设置正确。这是最重要的。我知道你已经做了所有这些事情。但我要求你确定一下。
-
@SivajeeBattina 我仔细检查了数据源和委托方法。
-
@Kiran 你设置断点并测试了吗?
-
这个问题似乎是由于调用了一个编写 tableview 方法的类。您是否尝试在 ViewDidAppear 方法中设置委托和数据源。请尝试一下,如果您成功了,请告诉我。
标签: ios objective-c uitableview uiview uiviewcontroller