Iphone 如何像UITableView一样对UIScrollView行重新排序
我正在创建一个应用程序,其中我需要对uiscrollview行重新排序,类似于uitableview,因此我想知道如果可以,那么请如何帮助我…Iphone 如何像UITableView一样对UIScrollView行重新排序,iphone,objective-c,ios,uiscrollview,Iphone,Objective C,Ios,Uiscrollview,我正在创建一个应用程序,其中我需要对uiscrollview行重新排序,类似于uitableview,因此我想知道如果可以,那么请如何帮助我…uitableview可以轻松地对行重新排序,如果您需要获得相同的行为,在 UISCRoVIEW 你需要自己做这一切……< /P> < P>如果你想做这样的事情,那么我假设你没有考虑使用带有自定义UITababVIEW单元格的表视图吗?如果要创建类似gallery的内容,请尝试创建一个UITableViewCell,其中包含一些自定义视图,其中包含图像和需
uitableview
可以轻松地对行重新排序,如果您需要获得相同的行为,在<代码> UISCRoVIEW 你需要自己做这一切……< /P> < P>如果你想做这样的事情,那么我假设你没有考虑使用带有自定义UITababVIEW单元格的表视图吗?如果要创建类似gallery的内容,请尝试创建一个UITableViewCell,其中包含一些自定义视图,其中包含图像和需要显示的所有其他数据:
.h文件
#import <UIKit/UIKit.h>
#import "ClipView.h"
@interface ClipViewCell : UITableViewCell {
}
@property (nonatomic, retain) NSMutableArray *clipViews;
- (void)setVisibleClipViewsQuantity:(NSUInteger)quantity;
@end
#导入
#导入“ClipView.h”
@接口ClipViewCell:UITableViewCell{
}
@属性(非原子,保留)NSMutableArray*ClipView;
-(void)setVisibleClipViewsQuantity:(nsInteger)数量;
@结束
.m文件
#import "ClipViewCell.h"
@implementation ClipViewCell
@synthesize clipViews;
- (id)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style
reuseIdentifier:reuseIdentifier];
if (self) {
self.clipViews = [NSMutableArray array];
CGFloat xMargin = 5.0f;
for (int i = 0; i < 3; i++) {
ClipView *clipView = [[[ClipView alloc] initWithFrame:CGRectMake(xMargin,
5.0f,
0.0f,
0.0f)] autorelease];
[clipViews addObject:clipView];
xMargin = clipView.frame.origin.x + clipView.frame.size.width + 5.0f;
[self addSubview:clipView];
}
}
return self;
}
- (void)setVisibleClipViewsQuantity:(NSUInteger)quantity {
for (int i = quantity; i < 3; i++) {
ClipView *clipView = [clipViews objectAtIndex:i];
clipView.hidden = YES;
}
for (int i = 0; i < quantity; i++) {
ClipView *clipView = [clipViews objectAtIndex:i];
clipView.hidden = NO;
}
}
- (void)setSelected:(BOOL)selected
animated:(BOOL)animated {
return;
}
- (void)dealloc {
self.clipViews = nil;
[super dealloc];
}
@end
#导入“ClipViewCell.h”
@ClipViewCell的实现
@综合clipViews;
-(id)initWithStyle:(UITableViewCellStyle)样式
reuseIdentifier:(NSString*)reuseIdentifier{
self=[super-initWithStyle:style
reuseIdentifier:reuseIdentifier];
如果(自我){
self.clipView=[NSMutableArray];
CGFloat xMargin=5.0f;
对于(int i=0;i<3;i++){
ClipView*ClipView=[[ClipView alloc]initWithFrame:CGRectMake(xMargin,
5.0f,
0.0f,
0.0f)]自动释放];
[clipView添加对象:clipView];
xMargin=clipView.frame.origin.x+clipView.frame.size.width+5.0f;
[自添加子视图:clipView];
}
}
回归自我;
}
-(void)setVisibleClipViewsQuantity:(NSInteger)数量{
for(int i=数量;i<3;i++){
ClipView*ClipView=[ClipView对象索引:i];
clipView.hidden=是;
}
对于(int i=0;i
其中“ClipView”是自定义UIView,上面显示数据
然后在UITableView视图控制器中使用表视图数据源方法,如:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger number = clips.count % 3 > 0 ? clips.count / 3 + 1 : clips.count / 3;
return number;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ClipViewCell *cell = nil;
int clipViewsQuantity = 0;
NSString *reuseIdentifier = @"clipCell";
if (indexPath.row == [tableView numberOfRowsInSection:0]-1) {
clipViewsQuantity = myLingoClips.count % 3 > 0 ? myLingoClips.count % 3 : 3;
}
else {
clipViewsQuantity = 3;
}
cell = (ClipViewCell *)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (cell == nil) {
cell = [[ClipViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
}
[cell setVisibleClipViewsQuantity:clipViewsQuantity];
int currentElement = indexPath.row * 3;
for (int i = 0; i < clipViewsQuantity; i++) {
ClipView *clipView = [cell.clipViews objectAtIndex:i];
// do something with the clipView here, like set another image
currentElement++;
}
return cell;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
NSInteger number=clips.count%3>0?clips.count/3+1:clips.count/3;
返回号码;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
ClipViewCell*单元格=零;
int clipViewsQuantity=0;
NSString*reuseIdentifier=@“clipCell”;
if(indexath.row==[tableView numberOfRowsInSection:0]-1){
ClipViewQuantity=MylingClips.count%3>0?MylingClips.count%3:3;
}
否则{
clipViewsQuantity=3;
}
cell=(ClipViewCell*)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
如果(单元格==nil){
cell=[[ClipViewCellAlloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
}
[单元格设置VisibleClipViewQuantity:ClipViewQuantity];
int currentElement=indexPath.row*3;
对于(int i=0;i
使用此功能,您可以轻松调整数据模型,以便使用标准UITableView功能重新排序。您想要什么?重新订购?您所说的uiscrollview行是什么意思?请详细说明您的问题。是的,UiTableView和uiscrollview行中类似的HAAPEN的重新排序是指用于在scrollview上显示的图像