2012-09-23 82 views
1

我有一個奇怪的問題與TableView。下面是一些代碼來澄清一切:TableView不會顯示提供的數據

我使用的標籤式窗格,在這裏這一權利僅僅是我的兩個ViewControllers之一:

正如你所看到的,我做的是建立一個的UIView和放置的tableView就在它的頂部。

#import "SuchenCtrl.h" 

@interface SuchenCtrl() 

@end 

@implementation SuchenCtrl 

@synthesize MainView; 
@synthesize Standort; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
// Do any additional setup after loading the view. 
    self.view = self.MainView; 

    [self.Standort.tableView setDelegate:self.Standort]; 
    [self.Standort.tableView setDataSource:self.Standort]; 

    [self.MainView addSubview:self.Standort.tableView]; 
} 

- (id)init { 
    self = [super init]; 

    if(self) { 
     CGRect rect = [[UIScreen mainScreen] applicationFrame]; 
     self.MainView = [[UIView alloc] initWithFrame:rect]; 
     [self.MainView setBackgroundColor:[UIColor blackColor]]; 

     //Alloc UITableViewController 
     self.Standort = [[UIStandort alloc] initWithStyle:UITableViewStylePlain]; 

     [self.Standort release]; 
     [self.MainView release]; 
    } 

    return self; 
} 

@end 

現在UIStandort是另一個簡單繼承自UITableViewController的類。它實現了顯示數據所需的全部功能。我試圖實現的所有表都顯示「測試」幾次,但它不會。表格很好地顯示,但只有空單元格。當我在類UIStandort中實現的一個函數斷點沒有被調用時,所以我的假設是委託和sourceData指向錯誤的類?不過,在將表格放在視圖之前,我明確地指定了這些內容。

UIStandort *如果有幫助,Standort聲明爲屬性retain和nonatomic。

#import "UIStandort.h" 

@interface UIStandort() 

@end 

@implementation UIStandort 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 0; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return 5; 
} 

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

    UITableViewCell* cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; 
    cell.textLabel.text = @"Test"; 

    [cell autorelease]; 

    return cell; 
} 

@end 

謝謝。

回答

3

對於段中的行數返回0。該文檔指出:

tableView中的段數。默認值是1。

你可以嘗試:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 
+0

哈哈,這並獲得成功。謝謝,這個問題解決了。 – user1692986

+0

@ user1692986太棒了!如果您想將其標記爲已解決,那麼將從隊列中清除它。 – FluffulousChimp