[英]-tableView:cellForRowAtIndexPath: is not getting called
I've UITableView
in UIViewController
and I've connected through outlet and delegete and datasource are assigned to self. 我在
UIViewController
有UITableView
,我通过outlet和delegete连接,数据源被分配给self。 numberOfSectionsInTableView
and numberOfRowsInSection
are getting called i tried by using NSLog
but cellForRowAtIndexPath
is not getting call my code looks like numberOfSectionsInTableView
和numberOfRowsInSection
正在调用我试过使用NSLog
但是cellForRowAtIndexPath
没有得到调用我的代码看起来像
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@" cellForRowAtIndexPath ");
static NSString *CellIdentifier = @"CurrencyCell";
CurrencyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CurrencyCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
}
new *Obj = [appdelegate.array objectAtIndex:indexPath.row];
cell.CurNameLabel.text = Obj.C_Name;
cell.textLabel.text = @"sdfnhsdfndsio;";
NSLog(@"C_Name %@", Obj.C_Name);
return cell;
}
can any one tel wer i'm making mistake Thanks in advance 任何一个电话我都会犯错误提前谢谢
It seems the numberOfSectionsInTableView
and numberOfRowsInSection
returned are 0.If this is the case then cellForRowAtIndexPath will not get called.. 似乎返回的
numberOfSectionsInTableView
和numberOfRowsInSection
是0.如果是这种情况,那么将不会调用cellForRowAtIndexPath。
From the comment above..it seems that "YourAppDelegate" variable is null
or yourArray is null
.Try keeping the break point on these delegates ,to check the values returned by them 从上面的注释..似乎“YourAppDelegate”变量为
null
或yourArray为null
尝试在这些委托上保留断点,以检查它们返回的值
try this add delegate and datasource in .h file like below.. 尝试在.h文件中添加委托和数据源,如下所示。
@interface AddProjectViewController : UIViewController<
UITableViewDataSource,UITableViewDelegate>
.....
@end
after in viewDidLoad:
put this code.. 在
viewDidLoad:
把这段代码..
- (void)viewDidLoad
{
yourTableView.delegate= self;
yourTableView.dataSource=self;
}
and at last try this in numberOfRowsInSection
method to return some int
value more than 0 最后在
numberOfRowsInSection
方法中尝试这个,返回一些大于0的int
值
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [yourArray count];//or any int value
}
It seems the numberOfSectionsInTableView
and numberOfRowsInSection
returned are 0 or may be another reason for this 似乎返回的
numberOfSectionsInTableView
和numberOfRowsInSection
是0或者可能是另一个原因
Carefully check below Points 仔细检查以下几点
1 if you are creating TableView from XIB the should set the datasource and delegate to the Files' Owner in. 1如果要从XIB创建TableView,则应设置数据源并委托给文件的所有者。
if You are creating it programatically then you should set the delegate and dataSource as below and don't forget to adopt the dataSourec
and delegate
for UItableView
in .h
如果你是编程创建它,那么你应该设置委托和数据源,如下,不要忘记采取
dataSourec
并delegate
了UItableView
在.h
YourViewController : UIViewController<UITableViewdelegate, UITableViewDatasource>
Put The Below line of Code just After the Line where you are creating the UITableView 将下面的代码行放在创建UITableView的行之后
tableViewObj.delegate= self;
tableViewObj.dataSource=self
2 Carefully check does your datasource
(whatever the name of Array) have data because whenever you create the number of rows you pass the array `count as given Below 2仔细检查您的
datasource
(无论Array的名称)是否有数据,因为每当您创建传递数组的行数时,计数如下所示
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int numberOfRows= [datasource count];
return numberOfRows;
// here check does the `numberOfRows` have nonzero value or just 0
if it retunes 0 then cellForAtIndexPath would not call .
}
I hope it'll helpful to You 我希望它对你有帮助
If you enabled multithreading concept in your app, even if you call reloadData
method on tableview
cellForRowAtIndexPath
won't be called sometimes. 如果在应用程序中启用了多线程概念,即使在
tableview
上调用reloadData
方法,有时也不会调用cellForRowAtIndexPath
。 So call realod method like this: 所以调用这样的realod方法:
[self performSelectorOnMainThread:@selector(reloadTable) withObject:self waitUntilDone:NO];
It may work. 它可能会奏效。
- (void)reloadTable
{
[self.tableView reloadData];
}
If you are not in multithreading environment, then you need to make sure tableviews
delegate
and datasource
are not null. 如果您不在多线程环境中,那么您需要确保
tableviews
delegate
和datasource
不为空。
Check the number values in your array in "numberOfRowsInSection" method. 使用“numberOfRowsInSection”方法检查数组中的数字值。 print your array before returning value.
在返回值之前打印您的数组。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%@",returnedArray);
return [returnedArray count];//
}
Also you can try sending some static number of rows in your method to check. 您也可以尝试在方法中发送一些静态行数来检查。
It looks like your array is getting null in that method. 看起来你的数组在该方法中变为null。
Hope it resolves your issue. 希望它能解决你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.