首页 > 其他 > 详细

Chapter 9 Editing UITableView

时间:2014-09-18 16:06:14      阅读:236      评论:0      收藏:0      [点我收藏+]

Chapter 9 Editing UITableView

 

 

1. 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. And you can load XIB file manually with NSBundle.

 

// Load header view

-(UIView*)headerView

{

    if(!_headerView)

    {

        [[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:self options:nil];

    }

    

    return _headerView;

}

 

 

2. When a new row was inserted into tableView, the data source also need to be inserted an new object. Because the role of a view object is to present model objects to the user, updating views without updating the model objects is not very useful.

 

3. Difference between reomveObjectIdenticalTo: and removeObject::

 

removeObject: goes to each object in the array and sends it the message isEqual:. A class can implement this method to return YES or NO based on its own determination.

 

removeObjectIdenticalTo:, on the other hand, removes an object if and only if it is the exact same object as the one passed in this message. 

 

 

4. Note that simply implementing tableView:moveRowAtIndexPath:toIndexPath: caused the reordering controls to appear. The model has to implementing the reorder method.

 

// DataSource implements tableView:moveRowAtIndexPath:toIndexPath 

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

{

    [[BNRItemStore sharedStore] moveItemFromIndex:sourceIndexPath.row toIndex:destinationIndexPath.row];

}

 

// Model of Array implement 

-(void)moveItemFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex

{

    if(fromIndex == toIndex)

    {

        return;

    }

    

    BNRItem *item = self.privateItems[fromIndex];

    [self.privateItems removeObjectAtIndex:fromIndex];

    [self.privateItems insertObject:item atIndex:toIndex];

}

 

 

 

 

 

 

Chapter 9 Editing UITableView

原文:http://www.cnblogs.com/1oo1/p/3979167.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!