问题描述
我知道标题已经足够说明了,我知道这个问题已被问过几次,但是在这种情况下我无法使它成功。
I know the title is illustrating enough, and I KNOW that this question has been ask a couple of times, but in this case I couldn't manage to make it work.
我已经使用过UITableViews并且它们都运行良好,但这一次,我甚至用其他工作副本检查了我的代码,但它无法正常工作。
I already have worked with UITableViews and they all have been working fine, but this time, I even checked my code with other working copies, but it is not working.
所以,这是故事:
我在故事板中的一个视图控制器中有一个表视图,其中包含一个名为的自定义类ContactViewController
,它使用名为的插座连接到代码favContactsTable
I have a table view in one of my view controller's in storyboard with a custom class named ContactViewController
, and it is connected to code using an outlet named favContactsTable
以下是相关部分来自.h和.m:
Here are related parts from its .h and .m :
ContactViewController.h
@interface ContactViewController : UIViewController <UITableViewDataSource>
// Other Stuff
.
.
@property (retain, nonatomic) IBOutlet UITableView *favContactsTable;
.
.
// Other Stuff
@end
这里是已实现的功能 UITableViewDataSource
协议:
And here is implemented functions of UITableViewDataSource
protocol :
ContactViewController.m
// Rest of the code
.
.
.
.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"TEST OUTPUT");
//Test
int a = 1; // Breakpoint
a++;
cell = [self.favContactsTable dequeueReusableCellWithIdentifier:@"FavContactCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FavContactCell"];
}
cell.textLabel.text = @"FAV";
.
.
.
}
我的视图控制器中有另一个按钮可重新加载此表的数据,但是当我按下它时没有触发断点并且没有打印日志,没有任何函数被调用。以下是该按钮的代码:
I have another button in my view controller that reloads data for this table, but when I press it none of the breakpoints is triggered and no log is printed, none of the functions are being called. Here's the code for that button :
- (IBAction)refreshTables:(id)sender
{
[self.favContactsTable reloadData];
}
我检查了几乎所有具有动态表视图的项目的部分这个,我无法弄清楚出了什么问题。
I checked almost every part with my other projects that has a dynamic table view like this, and I can't figure out what's wrong.
请不要提及其他类似的重复问题,因为我已经把它们全部读过(或者至少,大多数他们确定我不会为每个部分返回0行,我确定 favContactsTable
不是 nil
当我向它发送 reloadData
消息时......等等!
Please do not mention other similar questions as duplicates, because I already have read them all ( or at least, most of them ) and I'm sure I'm not returning 0 rows for each section, and I'm sure favContactsTable
is not nil
when I send reloadData
message to it and ... etc !
任何可能有帮助的想法非常感谢。
Any idea that may help is really appreciated.
推荐答案
@interface myViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
}
set delegate
set delegate
拖动到你的viewcontroller图标
drag to your viewcontroller icon
检查代码中的单元格标识符是否相同
check your cell identifier as same in your code also
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleTableCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"SimpleTableCell"];
}
return cell;
}
这篇关于UITableView - 未调用cellForRowAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!