关于在view当中增加toolbar的问题

来源:互联网 发布:淘宝助理5 for mac 编辑:程序博客网 时间:2024/05/29 19:21


在view当中,增加toolbar,往往会导致toolbar跟着tableview一起滚动。

为了改善这种状况,通常的做法是,将toolbar和tableview都加入到父类的view当中去。


其实比较简单的参考例子如下:


NSString * strfilepath = [[[NSBundlemainBundle] resourcePath] stringByAppendingPathComponent:@"bookname.plist"];

list = [[NSMutableArrayalloc] initWithContentsOfFile:strfilepath];

CGRect rectframe = CGRectMake(0, 0, 320, 460);

mytable =[[UITableViewallocinitWithFrame:rectframe style:UITableViewStylePlain];

mytable.delegate =self;

mytable.dataSource =self;

[self.viewaddSubview:mytable];

CGRect tframe;

CGRect bound;

bound = [[UIScreenmainScreen] applicationFrame];

tframe = CGRectMake(0, bound.size.height -50, bound.size.width,50);

toolbar  = [[UIToolbaralloc] initWithFrame:tframe];

toolbar.backgroundColor = [UIColorblueColor];

toolbar.autoresizingMask =UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;

medit = [[UIBarButtonItemalloc] initWithTitle:@"编辑"style:UIBarButtonItemStyleDone target:self action:nil];

toolbar.items = [NSArrayarrayWithObjects:medit,nil];

[self.viewaddSubview:toolbar];


//对于tableview的具体的读取内容的做法如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

UITableViewCell * cell = nil;

CGRect rectFrame = CGRectMake(0, 0, 320, 30) ;

cell = [[[UITableViewCellalloc] initWithFrame:rectFrame reuseIdentifier:@""]autorelease];

NSString *strCon = [listobjectAtIndex:indexPath.row];

UILabel *text = [[UILabelalloc] initWithFrame: cell.frame];

[text setFont:[UIFontboldSystemFontOfSize:20]];

[text setText:strCon];

[cell addSubview:text];

[strCon release];

return cell;


}



原创粉丝点击