2012-10-07 72 views
0

我想在我的iPhone應用程序來創建這樣一個觀點:分組的UITableView - 複製設置應用程序表視圖

enter image description here

我不知道究竟這是什麼控制的iOS,也許我可以在左側設置圖標和文字,在右側設置小標誌。

我實現了一個TableView中,有我可以設置這些東西,就像這樣:

[[cell textLabel] setText:customer.name]; 
    [[cell textLabel] setTextColor:[UIColor blackColor]]; 
    [[cell imageView] setImage:[UIImage imageNamed:@"icon.png"]]; 
    //[[cell detailTextLabel] setText:@"Awsome weather idag"]; 
    cell.accessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

但我怎麼可以把它的工作原理是在圖片看法?

+3

這是一個完全標準'UITableView'在組模式。你到底在做什麼? –

+0

是的你是對的。謝謝。 – Ali

回答

2

這是很簡單的,按照以下和疑慮的情況下的步驟檢查出UITableViewdocumentation

1.創建一個分組表視圖:

編程:

CGRect tableFrame = CGRectMake(0, 0, 200, 200); 

UITableView *tableView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewGroupedStyle]; 
tableView.delegate = self; 
tableView.dataSource = self; 

[self.view addSubview:tableView]; 

分配一個UITableViewController子類(普通情況):

MyTableViewController *controller [[MyTableViewController alloc] initWithStyle: UITableViewGroupedStyle]; 

[self.navigationController pushViewController:controller animated:NO]; 

通過界面生成:

  1. 展開實用程序菜單(右上角的圖標);
  2. 選擇你的表格視圖(點擊它);
  3. 點擊屬性檢查器(右上角第四個圖標);
  4. 在Table View下,單擊樣式下拉列表並選擇分組。

2.實現UITableViewDataSource協議:

基本上這三種功能添加到您的控制器。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

    // Return the number of sections. 

    return 1; 
} 

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

    // Return the number of rows in a given section. 

    return 5; 
} 

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

    // Configure the cells. 

    return cell; 
} 

3.配置細胞:

一個UITableViewCell的默認的樣式具有圖像視圖(的UIImageView),標題標籤(的UILabel)和附件視圖(UIView的)。您需要在您提供的圖像中複製表格視圖。

所以,你在tableView:cellForRowAtIndexPath:在尋找這樣的事情:

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

    static NSString * const cellIdentifierDefault = @"default"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierAccount]; 

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

    if (indexPath.section == 0) { 

     cell.imageView.image = [UIImage imageName:@"bluetooth_icon"]; 
     cell.textLabel.text = @"Bluetooth"; 

     // Additional setup explained later. 

    }else{ 

     if (indexPath.row == 0) { 

      cell.imageView.image = [UIImage imageName:@"general_icon"]; 
      cell.textLabel.text = @"General"; 
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

     }else{ 

      cell.imageView.image = [UIImage imageName:@"privacy_icon"]; 
      cell.textLabel.text = @"Privacy"; 
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

     } 

    } 

    return cell; 
} 

酒店accessoryType定義正在發生的事情出現在單元格的右側,附件類型的列表可以發現here

在第一個單元格(藍牙)中,您需要創建一個自定義附件視圖並將其分配給單元的accessoryView屬性。如何實現這是一個非常簡單的例子給出如下:

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

    static NSString * const cellIdentifierDefault = @"default"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierAccount]; 

    if (cell == nil) { 

     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierAccount]; 

     label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)]; 
     label.textAlignment = NSTextAlignmentRight; 

     cell.accessoryView = label; 

    }else{ 

     label = (UILabel *) cell.accessoryView; 

    } 

    cell.imageView.image = [UIImage imageName:@"bluetooth_icon"]; 
    cell.textLabel.text = @"Bluetooth"; 
    label.text = @"Off"; 

    return cell; 
} 

希望這有助於馬特烏斯

+0

+1獲得幫助。我會看看細節。 – Ali

1

調查UITableView部分。這就是將這些團體分開的原因。

+0

如何在右側設置'Flash'? – Ali

+0

什麼閃光燈?到圖像添加到細胞你的UIImageView *的ImageView =右側[[ALLOC的UIImageView] initWithImage:[UIImage的imageNamed:@ 「foo.png」]]; cell.accessoryView = ImageView的; [imageView發佈]; –

+0

如果您需要任何定製設計只是讓自己的.xib文件,並使它的UITableViewCell的子類。 Google自定義表格視圖單元格 –

2

用於快速輸出,你可以使用一些圖書館像 https://github.com/escoz/QuickDialog

普羅蒂普,以我的經驗,這樣的解決方案,讓你更糾結的變化時進來。

你只是想改變一次特定視圖一個特定的標籤有些時候,那不是戈納很容易在任何現成的解決方案。

+0

我很欣賞它。我會看看它。 +1爲你提供幫助。 – Ali

+0

我在項目中找不到任何storyboard或.xib文件。他們在哪裏?在QuickDialog中使用 – Ali

+0

,以編程方式製作UI –

相關問題