2013-04-13 24 views
0

第一關我新的iOS開發所以這可能是一個簡單的問題,的UITableViewController不會顯示單元格即時通訊創造

我有下面的代碼

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ; 

    cell.textLabel.text = @"Hello!"; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    NSLog(@"Creating cell for %i:%i", indexPath.section, indexPath.row); 

    return cell; 
} 

現在表所示,但所有的行都是空白的。細胞正在被創造。不知道它是否重要,但我不使用xib或故事板,所以我不知道它是否是一個樣式問題。

我真的在這裏什麼即時通訊做的黑暗。我試着遵循一些教程,每次我都會在空白桌子的同一個地方結束。

謝謝所有幫助!我打開思路和可能的教程等

+0

0是啊,我得到創建單元:0。或者,如果我設置第1和行3,那麼我得到: 創建細胞爲0:1 創建爲0電池:2 0創建細胞。 TIL:計算器意見不支持新線 – kjones1876

回答

1

(這更是一個評論,但它太大了評論欄。)

我複製你的方法恰好到我的.m文件,它的工作原理。該文件的其餘部分是這樣的:

@interface MYViewController() 

@end 

@implementation MYViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 640) style:UITableViewStylePlain]; 
    [table setDataSource:self]; 
    [table setDelegate:self]; 
    [self.view addSubview:table]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

我假設你設置數據源,因爲你得到的NSLogs打印。

+0

我沒有在viewDidLoad方法的任何代碼,太感謝你了,現在是時候撕開每一行,看看他們做什麼。謝謝 !! – kjones1876

+0

UITableView控制器**數據源**是程序查找如何加載表視圖單元格的位置。如果您沒有將.m文件設置爲數據源,那麼它會查看默認數據源 - 並忽略您的代碼。 (**委託**和執行'didSelectRowAtIndexPath'等操作也是如此) –

0

您確認的UITableView不隱藏,不具有0α,並且高於所有其他的意見?

0

如果顯示的數據有,當你走出去,回視場改變的可能性,我會建議使用

[self.yourTableViewObject reloadData]; 

這將調用所有的委託方法(獲得的部分,個人細胞)並重新填充你的表格視圖。

相關問題