2011-03-22 70 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。 這一定是你的情況。