簡體   English   中英

iPhone-使用Interface Builder的> 1個部分的靜態UITableView

[英]iPhone - Static UITableView with >1 sections using Interface Builder

我在應用程序中添加了一個新的TableView。 我將單元格類型更改為靜態,然后將一些標簽拖到單元格中。 現在我想以編程方式訪問單元。 例如:第3節中的第4單元格應通過google.com打開野生動物園。

我創建了一個新的UITableViewController類。 然后,我將節的數量更改為3,並向numberofcellsinsection方法添加了一個switch / case語句。

如果我運行該應用程序並打開表視圖,則該應用程序將崩潰。 有人可以幫我設置TableView嗎?

謝謝!

編輯

這是日志

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:

我找到了一種有效的解決方案。

我像這樣編輯cellForRowAtIndexPath方法:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];

    return cell;
}

現在,我可以使用if語句訪問靜態單元格,例如:

    -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 2){

    if (indexPath.row == 1){

            NSLog(@"Tap");

            [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"]];       
          }
    }        
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM