Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

NSMutableArray 添加移动位置函数

$
0
0

MoveArray.h@interface NSMutableArray (HF)
- (void)moveObjectFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex;


#import "MoveArray.h"


@implementation NSMutableArray (HF)
- (void)moveObjectFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex
{

    if (toIndex != fromIndex && fromIndex < [self count] && toIndex< [self count]) {

        id obj = [self objectAtIndex:fromIndex];
        [obj retain];
        [self removeObjectAtIndex:fromIndex];
        if (toIndex >= [self count]) {
            [self addObject:obj];
        } else {
            [self insertObject:obj atIndex:toIndex];
        }
        [obj release];
    }
}




@end:
作者:hufeng825 发表于2013-2-3 1:52:36 原文链接
阅读:104 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>