2013-04-04 65 views
0

我想在UITableView中添加數據源。我嘗試以下,但遺憾的是它沒有工作:UITableView和數據源

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

// Customize the appearance of table view cells. 
- (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]; 
    } 

    // Set the data for this cell: 

    cell.textLabel.text = [_classCellview objectAtIndex:indexPath.row]; 
    cell.detailTextLabel.text = @"One"; 
    cell.detailTextLabel.text = @"Two"; 



    // set the accessory view: 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 
} 
+0

是否調用了cellForRowAtIndexPath? – SG1 2013-04-04 21:08:26

+1

你是什麼意思的「沒有工作」? – tilo 2013-04-04 21:08:49

+0

我看不到'tableView:numberOfRowsInSection:'的實現,'UITableViewDataSource'是必需的。你可以張貼嗎? – MishieMoo 2013-04-04 21:13:59

回答

0

cell.textLabel.text = [_classCellview objectAtIndex:indexPath.row];

你告訴表有8個部分,但你不採取從section填充單元格時考慮的索引路徑。索引路徑具有(在表格視圖的情況下)兩個值:一個section和一個row。你需要他們都知道你在處理什麼細胞。所以,你可能會得到相同的內容在你的表的每個部分重複。 (但是,如果你告訴我們究竟是什麼問題,它會有所幫助。)

+0

我有表格顯示,但我想標籤字段「一」和「兩個」顯示在表內。 – 2013-04-04 22:40:29

+0

在這種情況下,看看你在用細胞的細節標籤做什麼。您將'@「一個」''分配給它的'text'屬性,然後在下一行分配'@「兩個」''到同一個標籤。一個標籤一次只能有一個值 - 如果您想要「一個兩個」,您應該首先組合字符串並將結果分配給標籤。 – Caleb 2013-04-05 02:00:29

相關問題