【发布时间】:2014-08-11 19:57:44
【问题描述】:
这就是故事。我有一个简单的应用程序,我在其中使用 2 个选项卡,它们都带有 UITableView。第一个选项卡/视图称为"Favorites",第二个称为"My Profile." 此外,我有一个名为"CustomViewCell.xib" 的自定义UITable 单元格,具有相同名称的标识符。 FavoritesViewController 是 UITableViewController 的子类,它运行良好。但是对于ProfileViewController,我使用的是普通的ViewController,因为我不希望整个视图都是UitableView。为此,我将以下内容发送至ProfileViewController.h:
@interface ProfileViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) IBOutlet UITableView *tableView;
然后在 ProfleViewController.m 文件的viewDidLoad 中我有:
[self.tableView registerNib:[UINib nibWithNibName:@"CustomViewCell" bundle:nil]
forCellReuseIdentifier:@"CustomViewCell"];
以下方法的实现与其他正在工作的选项卡中一样:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.myArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Here I am customizing the cell and returning it.
}
当我运行应用程序时,单元格的高度是正确的,但是是空的。 为了调试,我在 cellForRowAtIndexPath 之前放置了一个断点,并且应用程序运行时不会出现不应出现的错误。因此,该程序甚至没有使用这种方法。所以,我认为这就是单元格为空的原因。你们知道是什么导致它跳过这个特定的方法吗?因为我是新手,你也可以用更简单的术语解释一下吗?
【问题讨论】:
-
您是否将 vc 分配为 tableview 的委托/数据源?在 viewdidload 中:self.tableview.delegate=self; self.tableview.datasource=self
-
你跳过了代码中最重要的部分,留下了不相关的部分
-
你是对的。谢谢你,先生!如此愚蠢的错误。
标签: xcode uitableview ios7 uiviewcontroller