2012-10-19 36 views
1

UITableViewUIViewController,我已經連接通過出口和delegete和數據源分配給自己。 numberOfSectionsInTableViewnumberOfRowsInSection越來越叫我嘗試用NSLogcellForRowAtIndexPath沒有得到調用我的代碼看起來像-tableView: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; 
} 

可以在任何一個電話WER我正在提前犯錯誤感謝

+1

你有連接代理和數據源也在IB –

+0

亞我已經連接 –

+0

你在'numberOfSectionsInTableView'和'numberOfRowsInSection'返回什麼值? – mttrb

回答

6

看來numberOfSectionsInTableView和返回numberOfRowsInSection是0。如果是這樣的話,那麼會的cellForRowAtIndexPath不會被調用..

從評論above..it似乎「YourAppDelegate」變量null或yourArray是null。嘗試保持對這些代表的破發點,以檢查他們的返回值

+0

雅你的權利我的陣列爲空謝謝一噸:) –

4

嘗試像下面.h文件中這一 附加委託和數據源..

@interface AddProjectViewController : UIViewController< 
UITableViewDataSource,UITableViewDelegate> 
..... 
@end 

viewDidLoad:把這個代碼..

- (void)viewDidLoad 
    { 
     yourTableView.delegate= self; 
     yourTableView.dataSource=self; 
    } 

,並在最後嘗試這種在numberOfRowsInSection方法返回一些int值大於0

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [yourArray count];//or any int value 
} 
+0

我做到了作爲 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)部分{[0}}返回[appdelegate.array count]; } –

+0

你檢查你的數組是不是零? –

+0

雅你的權利我的陣列爲空謝謝一噸:) –

0

在「numberOfRowsInSection」方法中檢查數組中的數字值。在返回值之前打印您的數組 。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    NSLog(@"%@",returnedArray); 
    return [returnedArray count];// 
} 

你也可以嘗試發送一些靜態數量的行在你的方法來檢查。

看起來您的數組在該方法中變爲空。

希望它能解決您的問題。

2

似乎回到了numberOfSectionsInTableViewnumberOfRowsInSection是0或者可能是另一個原因

下面仔細檢查點

1,如果你是從XIB創建TableView中的應設置數據源和委託文件的所有者在。

如果你是編程創建它,那麼你應該設置委託和數據源,如下,不要忘記採取爲UItableViewdataSourecdelegate.h

YourViewController : UIViewController<UITableViewdelegate, UITableViewDatasource> 

把代碼的下面一行剛過你在哪裏創建的UITableView

 tableViewObj.delegate= self; 
     tableViewObj.dataSource=self 

仔細檢查線路做你的datasource因爲每當你創建的行數你傳遞數組(無論數組的名字)有數據`算作下面給出

- (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 . 
    } 

我希望它會幫助你

+0

雅你的權利我的陣列是空謝謝一噸:) –

1

如果啓用多線程概念在你的應用程序中,即使你打電話reloadData方法tableviewcellForRowAtIndexPath有時不會被調用。因此請致電realod方法如下:

[self performSelectorOnMainThread:@selector(reloadTable) withObject:self waitUntilDone:NO]; 

它可能會工作。

- (void)reloadTable 
{ 
    [self.tableView reloadData]; 
} 

如果你不是在多線程環境中,那麼你需要確保tableviewsdelegatedatasource不爲空。

+0

其工作正常我..感謝迪 – Hari1251

相關問題