2013-03-06 25 views
3

我有一個應用程序(導航控制器),其中第二個控制器是一個表視圖控制器。我能夠通過segue發送我所需的數據,但無法以編程方式更新tableview中的條目。UITableView&Controller給我空表視圖

我是IOS新手。

這是我的頭文件

#import <UIKit/UIKit.h> 
@interface HCIResultListViewController : UITableViewController 

@property (strong,nonatomic) NSMutableDictionary *resultList; 
@property (strong, nonatomic) IBOutlet UITableView *tableListView; 

@end 

這是我的執行文件。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    #warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 0; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
#warning Incomplete method implementation. 
// Return the number of rows in the section. 
return 0; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"HelloCell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil){ 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
} 

cell.textLabel.text = @"Hello"; 

// Configure the cell... 

return cell; 
} 

誰能告訴我如何與實現代碼如下&控制器工作?

我沒有經歷幾個文檔和示例,但真的想不出瞭解

+0

'numberOfRowsInSection'&'numberOfSectionsInTableView'返回0號碼 – 2013-03-06 10:40:56

+0

非常抱歉這個問題!只是一個小俯瞰! – 2013-03-06 11:59:28

回答

1

你需要指定表視圖行和段數。喜歡這個。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     #warning Potentially incomplete method implementation. 
     // Return the number of sections. 
     return 1; 
    } 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
    #warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    return [sourceData Count]//i.e., 10; 
    } 

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    static NSString *CellIdentifier = @"HelloCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil){ 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 

    cell.textLabel.text = @"Hello"; 

    // Configure the cell... 

    return cell; 
    } 
1

,你會想到什麼在你UITableView如果你設置了numberOfRowsInSection爲0?

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
#warning Incomplete method implementation. 
// Return the number of rows in the section. 
return 0; // it should be size of your Array or List 
} 

你應該行數更改爲數組大小或任何數據你是內UITableView

1

你需要返回至少1至能夠看到一些數據填充

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
1

tableView的段數是0!使1

1

它可以幫助你

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
#warning Incomplete method implementation. 
// Return the number of rows in the section. 
return 4; 
} 
1

更換你的方法是:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
    #warning Potentially incomplete method implementation. 
    return 1; 
    } 
1

那北京時間正是蘋果的模板,通過陳述的意思是:

#warning Potentially incomplete method implementation. 

你需要有返回適當的值。 從numberOfSectionsInTableView返回1如果你只有1個部分(這是我想說的正常情況)。 然後返回要從numberOfRowsInSection填充的行數。這可能是一個數組的數量或取數據集的數量,或者是一些硬編碼的值/常數值(如果它不是動態的)。

cellForRowAtIndexPath然後將被稱爲每個行/區域組合的最大值,但可能僅限於那些從開始可見或者即將滾動到可見區域的單元格。

0
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{  
    //warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    // 
    return 1; 
} 

按照這個數據源法說,作爲數列要求,你必須返回0,所以不會產生任何行所以也不會產生細胞,從而按照我們的要求,靜態否則動態生成的行至少1行返回。