2011-03-22 122 views
0

我知道这个问题一再被问过。我试过所有给定的解决方案,但仍然无法正常工作。我已经设置了数据源和委托到我的表视图,并将其设置为我的指针。ReloadData不会触发cellForRowAtIndexPath

这里是我的代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  { 
NSLog(@"%i", resultSoap.count); 
return resultSoap.count; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell. 

NSString *cellValue = [resultSoap objectAtIndex:indexPath.row]; 
cell.textLabel.text = cellValue; 
NSLog(@"Celldisplay"); 

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

return cell; 
} 

我已经在我的viewDidLoad:方法称为reloadData。事情是,它发射了numberOfRowsInSection:方法,我得到的行数是正确的,但它并没有触发这个cellForRowAtIndexPath:方法。

任何解决方案?

+0

它返回多少行?在调试模式下,你能看到resultSoap的内容吗? – Peres 2011-07-07 10:15:14

回答

-3

请在您的合适方法中添加波纹管代码。

,如果你有需要简单的控制器,并添加表视图比

在你的头文件的.h

#import <UIKit/UIKit.h> 
@interface TaskAndTax : UIViewController<UITableViewDelegate, UITableViewDataSource> 
{ 
    IBOutlet UITableView *MyTableView; 
} 
@property (nonatomic, retain) UITableView *MyTableView; 
@end 

,并在您.m文件

@synthesize MyTableView; 

-(void) viewWillAppear:(BOOL)animated 
{ 
    [MyTableView reloadData]; 
} 

并请连接IBOutlet中中我们的案例中的TableView将它的MyTableView添加到XIB文件中的TableView中。 In My case Its getclientTable.

0

使用此代码:

urtableview.delegate = self; 
urtableview.datasource = self; 

声明resultsoap阵列在你的代码后。

0

当表视图数据源数组“resultsoap”为空时,必须由于调用表的重装方法。 确保您的数据源数组不为空,并检查数组是否保存了对象。

因为如果numberOfRowsInSection返回0,则可能不会调用cellForRowAtIndexPath。 这一定是你的情况。