你的位置:首页 > 软件开发 > 操作系统 > iOS Programming Editing UITableView

iOS Programming Editing UITableView

发布时间:2015-05-12 20:00:30
iOS Programming Editing UITableView 1.1 Editing mode  UITableView has an editing property, and when this property is set to YES, th ...

iOS Programming Editing UITableView

iOS Programming Editing UITableView

1.1 Editing mode 

UITableView has an editing property, and when this property is set to YES, the UITableView enters editing mode.

UITableVIew有一个editing property,当属性设置为YES时,UITableView设置为editing mode。

Depending on how the table view is configured, the user can change the order of the rows, add rows, or remove rows. Editing mode does not allow the user to edit the content of a row.

根据tableview 如何配置,用户可以改变row的order,添加row,移除row,但是编辑模式却不能允许增加行。

That the table view uses the word "header" in two different ways: There can be a table header and there can be section headers. Likewise, there can be a table footer and section footers.

table view 有table header 和section header。类似的也有table footer 和section footer。 

Notice that headerView is a strong property. This is because it will be a top-level object in the XIB file; you use weak references for objects that are owned (directly or indirectly) by the top-level objects。

注意到你使用了strong 属性。那是因为headerView 将是xib文件的最上层。我们使用弱引用指向属于最上层的对象。

 

XIB files are typically used to create the view for a view controller, but they can also be used any time you want to lay out view objects, archive them, and have them loaded at runtime.

xib文件一般用来为view controller 创建新的view。但是他们也可以用在任何你像lay out view object,获取他们,在运行时得到他们。

step 1

Create a new file (Command-N). From the iOS section, select User Interface, choose the Empty template, and click Next

iOS Programming Editing UITableView

Drag a UIView onto the canvas. Then drag two instances of UIButton onto that view. You will then want to resize the UIView so that it just fits the buttons; however, Xcode will not let you: the size is locked. To unlock the size, select the UIView on the canvas and open the attributes inspector. Under the Simulated Metrics section, select None for the Size option.

iOS Programming Editing UITableView

iOS Programming Editing UITableView

iOS Programming Editing UITableView

iOS Programming Editing UITableView

 

To load a XIB file manually, you use NSBundle.

为了手动加载XIB 文件,你需要NSBundle。

This class is the interface between an application and the application bundle it lives in.

这个类是application和application bundle 的接口。

When you want to access a file in the application bundle, you ask NSBundle for it.

当你需要从application bundle 中获取一个文件时,需要从NSBundle中获取。

An instance of NSBundle is created when your application launches, and you can get a pointer to this instance by sending the message mainBundle to NSBundle.

一个NSBundle的实例在应用启动的时候就已经创建了。你可以通过发送一个消息mainBundle 给NSBundle 获取一个指向它的指针。

Once you have a pointer to the main bundle object, you can ask it to load a XIB file.

一旦你获取了指向main bundle 的指针,你就可以要求它加载一个XIB文件了。

Notice that this is a getter method that does more than just get.

注意这个getter方法又不仅仅是一个get方法。

This is a common pattern: Lazy Instantiation puts off creating the object until it is actually needed.

这是一个常用的模式:延迟实例化,只有当它确实需要的时候才实例化该对象。

In some cases this approach can significantly lower the normal memory footprint of your app.

在一些情况下这确实能降低你的内存。

- (UIView *)headerView

{

// If you have not loaded the headerView yet... if (!_headerView) {

// Load HeaderView.xib

}

[[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:self

options:nil];

return _headerView; }

 

notice that you passed self as the owner of the XIB file. This ensures that when the main NSBundle is parsing the resultant NIB file at runtime, any connections to the File's Owner placeholder will be made to that BNRItemsViewController instance.

你也注意到传递self 给xib 文件的owner。这确保了当main NSBundle 解析NIB文件的结果时,任何连接到FIle's owner placeholder的都将在BNRItemsViewController 实例。

 

 UIView *view=self.headerView;

    [self.tableView  setTableHeaderView:view];

 

In addition, any object can load a XIB file manually by sending the message loadNibNamed:owner:options: to the application bundle.

任何想加载xib 文件的对象可以发送一个loadNibNamed:owner:options:给application bundle。

 

UIViewController's default XIB loading behavior uses the same code.

The only difference is that it connects its view outlet to the view object in the XIB file.

唯一不同的区别是它在XIB 文件里 连接view outlet 到view object . 

Imagine what the default implementation of loadView for UIViewController probably looks like:

- (void)loadView

{

原标题:iOS Programming Editing UITableView

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。