I've UITableView
in UIViewController
and I've connected through outlet and delegete and datasource are assigned to self.numberOfSectionsInTableView
and numberOfRowsInSection
are getting called i tried by using NSLog
but cellForRowAtIndexPath
is not getting call my code looks like
- (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..
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
try this
add delegate and datasource in .h file like below..
@interface AddProjectViewController : UIViewController<
UITableViewDataSource,UITableViewDelegate>
.....
@end
after in viewDidLoad:
put this code..
- (void)viewDidLoad
{
yourTableView.delegate= self;
yourTableView.dataSource=self;
}
and at last try this in numberOfRowsInSection
method to return some int
value more than 0
- (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
Carefully check below Points
1 if you are creating TableView from XIB the should set the datasource and delegate to the Files' Owner in.
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
YourViewController : UIViewController<UITableViewdelegate, UITableViewDatasource>
Put The Below line of Code just After the Line where you are creating the 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
- (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. So call realod method like this:
[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.
Check the number values in your array in "numberOfRowsInSection" method. 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.
Hope it resolves your issue.