- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{workouttableVIEwCell *cell = (workouttableVIEwCell *)[tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr];// Configure the cell...if (cell == nil) { cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:CellIDentifIEr];}[cell.addbutton setTitle:(Nsstring *)indexPath forState:UIControlStateApplication];[cell.textLabel setText:[Nsstring stringWithFormat:@"Row %i in Section %i",[indexPath row],[indexPath section]]];NSInteger sectionsAmount = [tableVIEw numberOfSections];NSInteger rowsAmount = [tableVIEw numberOfRowsInSection:[indexPath section]];if ([indexPath section] == sectionsAmount - 1 && [indexPath row] == rowsAmount - 1) { NSLog(@"Reached last cell"); [cell.addbutton setHIDden:NO]; if (lc == NO) {[[self tableVIEw] reloadData]; lc = YES; }} return cell; }解决方法 以下UItableVIEwDataSource方法将帮助您返回部分中可用的确切行数.在这里,你需要返回额外的,因为你想拥有最后一个按钮.
- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section { return yourRowCount + 1;}
现在在下面的方法中,您将使用indexpath.row检查行号
- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath { static Nsstring *lastCellIDentifIEr = @"LastCellIDentifIEr"; static Nsstring *workoutCellIDentifIEr = @"WorkoutCellIDentifIEr"; if(indexPath.row==(yourRowCount+1)){ //This is last cell so create normal cell UItableVIEwCell *lastcell = [tableVIEw dequeueReusableCellWithIDentifIEr:lastCellIDentifIEr]; if(!lastcell){ lastcell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:lastCellIDentifIEr]; CGRect frame = CGRectMake(0,320,40); UIbutton *abutton = [UIbutton buttonWithType:UIbuttonTypeCustom]; [abutton addTarget:self action:@selector(btnAddRowTapped:) forControlEvents:UIControlEventtouchUpInsIDe]; abutton.frame = frame; [lastcell addSubvIEw:abutton]; } return lastcell; } else { //This is normal cells so create your worktouttablecell workouttableVIEwCell *cell = (workouttableVIEwCell *)[tableVIEw dequeueReusableCellWithIDentifIEr:workoutCellIDentifIEr]; //Configure your cell }}
或者你可以像编程一样创建UIVIEw并将其设置为FooterVIEw,如@student在评论代码中所建议的那样,
CGRect frame = CGRectMake(0,40);UIVIEw *footerVIEw = [[UIVIEw alloc] initWithFrame:frame];UIbutton *abutton = [UIbutton buttonWithType:UIbuttonTypeCustom];[abutton addTarget:self action:@selector(btnAddRowTapped:) forControlEvents:UIControlEventtouchUpInsIDe];abutton.frame = frame;[footerVIEw addSubVIEw:abutton];[yourtableNmae settableFooterVIEw:footerVIEw];
声明方法如下
-(IBAction)btnAddRowTapped:(ID)sender{ NSLog(@"Your button tapped");}总结
以上是内存溢出为你收集整理的ios – 如何使UIButton仅出现在最后一个单元格中?全部内容,希望文章能够帮你解决ios – 如何使UIButton仅出现在最后一个单元格中?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)