English 中文(简体)
可上诉意见:我想采用一种易于修改章节和行文的方法(删除)。
原标题:UITableView: I want to use an approach in which it is easy modify sections and rows (add, remove).

我们的表态每个月都有变化。 很难修改章节和行文(删除)。 我需要扫描每一种可调用的电文,并改变这种方法。 采用开关办法。 我不需要更明智的做法。

I posted my code for two methods but in reality I have to modify 5 methods.

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

 switch (section) 
 {
    case 0:
    {
        rows = 3;
        break;
    }            
    case 1:
    {
        rows = 4;
        break;
    }
    case 2:
    {
        rows = 4;
        break;
    }
    case 3:
    {
        rows = 4;
        break;
    }
    case 4:
    {
        rows = 7;
        break;
    }

    default:
        rows = 1;
        break;
 }

 return rows;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 switch (indexPath.section) 
 {
    case 0:
    {
        switch (indexPath.section) 
        {
            case 0:
            {
                break;
            }
            case 1:
            {
                break;
            }
            case 2:
            {
                break;
            }                    
            default:
                break;
        }

        break;            
     }
  }
}
最佳回答

Create a class say TableManager

Pass your table view to this class and let this class provide the data for all your tableviews. Differentiate between the tableviews by settings tag values to them.

因此,现在你将掌握你在这个类别中的所有桌子。

Instead of the numbers in the switch case use enum. It will increase readability in your code.

根据您的实际要求,你可以从名单中操纵这一类行为。

Let me provide some code:

定义一个统计员

typedef enum { FIRST_TABLE, SECOND_TABLE, THIRD_TABLE } TableViews;


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

[TableManager getNumberOfRowsForTableView:tableView];

}

阁下

+ (NSInteger)getNumberOfRowsForTableView:(UITableView*)theTableView
{

if(theTableView.tag == FIRST_TABLE) //FIRST_TABLE is an enum
{
 //Your conditions goes here
 return 3;
}

}
问题回答

如果你可以直接修改其内容和<编码> 查询簿,则只能根据这一条建立<编码>可调取的<<<>可调用的>密码>。 与我一样工作。

I created this class that does exactly what you want: https://github.com/Morbix/TableManager

表格管理的基本使用

import TableManager // 1 - import TableManager

class ViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let data = (1...1_000).map { "Row ($0)" }

        data.forEach { element in
            let row = tableView.addRow() // 2 - Add a row

            row.setConfiguration { (row, cell, indexPath) in // 3 - And configure it 
                cell.textLabel?.text = element
            }
        }

        tableView.reloadData()
    }

}

你可以增加第19节和第24节,控制可见度、召集头和脚步等等。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签