相关疑难解决方法(0)

滑动以删除单元格会导致tableViewHeader与单元格一起移动

tableViewHeaderUITableView在iOS 8中遇到了一个奇怪的错误.当在一个单元格上滑动以显示删除按钮(标准iOS滑动到删除)时,它会tableViewHeader随着正在滑动的单元格一起移动.当我轻扫单元格时,标题的移动方式与刷过单元格的方式相同.表视图中没有其他单元格被移动,只有标题和任何单元格被刷过.我在iOS 7上测试过这个没有遇到过这个问题.对我来说,这似乎是tableViewHeaderiOS 8中的一个错误,因为它只出现在这个版本中,似乎永远不会发生.我认为没有理由将标题包含在swipe-to-delete中.

下面只是一个模型.在应用程序中滑动删除是默认的iOS,没有自定义.

下面只是一个模型. 在应用程序中滑动删除是默认的iOS,没有自定义.

objective-c uitableview ios ios8

54
推荐指数
3
解决办法
7921
查看次数

在Interface Builder中设计UITableView的节头

我有一个xib文件UITableView,我想使用委托方法添加自定义节标题视图tableView:viewForHeaderInSection:.有没有可能设计它Interface Builder,然后以编程方式更改它的一些子视图的属性?

UITableView有更多的章节标题,以便创建一个UIViewInterface Builder和返回这是行不通的,因为我不得不重复它,但没有做任何好的方法.归档和取消归档它不适用于UIImages所以UIImageViews会显示空白.

此外,我不想以编程方式创建它们,因为它们太复杂,结果代码很难读取和维护.

编辑1:这是我的tableView:viewForHeaderInSection:方法:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    if ([tableView.dataSource tableView:tableView numberOfRowsInSection:section] == 0) {
        return nil;
    }

    CGSize headerSize = CGSizeMake(self.view.frame.size.width, 100);

    /* wrapper */

    UIView *wrapperView = [UIView viewWithSize:headerSize];

    wrapperView.backgroundColor = [UIColor colorWithHexString:@"2670ce"];

    /* title */

    CGPoint titleMargin = CGPointMake(15, 8);

    UILabel *titleLabel = [UILabel labelWithText:self.categoriesNames[section] andFrame:CGEasyRectMake(titleMargin, CGSizeMake(headerSize.width - titleMargin.x * 2, 20))]; …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c interface-builder uitableview ios

27
推荐指数
2
解决办法
4万
查看次数

iPhone UITableView部分

我一直在编写一个UITableView,每个单元格都会推出一个新的视图,我只想添加两个新的部分,一个是男性,一个是女性,第一个和第二个声音需要在男性部分,第三个声音需要在女性部分.

#import "FirstLevelViewController.h"
#import "SecondLevelViewController.h"
#import "DisclosureDetailController.h"
#import "SecondVoiceController.h"
#import "ThirdVoiceController.h"



@implementation FirstLevelViewController
@synthesize controllers;

-(void)viewDidLoad {
    self.title = @"Voices";

    NSMutableArray *male = [[NSMutableArray alloc] init];


    DisclosureDetailController *th = [DisclosureDetailController alloc];
    th.title = @"First Voice";
    [male addObject:th];
    [th release];

    SecondVoiceController *array2 = [SecondVoiceController alloc];
    array2.title = @"Second Voice";
    [male addObject:array2];
    [array2 release];

    ThirdVoiceController *array3 = [ThirdVoiceController alloc];
    array3.title = @"Third Voice";
    [male addObject:array3];
    [array3 release];




    self.controllers = male;
    [male release];
    [super viewDidLoad];
}

-(void)viewDidUnload {

    self.controllers = nil;
    [super viewDidUnload]; …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c uitableview

8
推荐指数
1
解决办法
3万
查看次数

如何将自定义单元格设置为UITableView的页眉或页脚

我使用Xib文件而不是故事板.我创建了一个包含一些虚拟数据的表视图.它的工作正常,现在我已经创建了一个带有一些标签和textFields的自定义单元格.如何将其用作UITableView的页眉或页脚?

uitableview custom-cell ios swift uitableviewsectionheader

8
推荐指数
2
解决办法
1万
查看次数

更改UITable部分backgroundColor而不丢失部分标题

我已经更改了tableviews部分的backgroundColor/backgroundImage.
我使用普通的tableView.不用担心,使用此代码可以正常工作:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 728, 40)] autorelease];
sectionView.backgroundColor = [UIColor greenColor];

//For using an image use this:
//sectionView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"whiteBackground.png"]];

return sectionView;
}  
Run Code Online (Sandbox Code Playgroud)

现在的问题是,章节标题已经消失.

我正在使用以下代码设置该部分的标题:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]){
    return @"";
} else {    
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
    return [sectionInfo name];
}


}
Run Code Online (Sandbox Code Playgroud)

如果我不使用,我会得到章节标题

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section  
Run Code Online (Sandbox Code Playgroud)

需要你的帮助.
非常感谢.

编辑1:

感谢Mutix:

就我而言,答案是:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { …
Run Code Online (Sandbox Code Playgroud)

title background-color sectionheader ios

7
推荐指数
2
解决办法
9123
查看次数

在UITableView中自定义标题

我正在尝试在UITableView中自定义标题.我无法在故事板中找到它,所以我开始添加UIView和UILabel.

这是我的代码:

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let headerView = UIView(frame: CGRectMake(0,0, tableView.frame.size.width, 60))
    headerView.backgroundColor = UIColor.cyanColor()
    headerView.layer.borderColor = UIColor.whiteColor().CGColor
    headerView.layer.borderWidth = 1.0;

    let headerLabel = UILabel(frame: CGRectMake(5,2, tableView.frame.size.width - 5, 30))
    headerLabel.text = sectionTitle  (this is a variable)
    headerLabel.textAlignment = NSTextAlignment.Center
    headerLabel.font = UIFont(name: "AvenirNext", size: 18)
    headerLabel.textAlignment = NSTextAlignment.Center;
    headerView.addSubview(headerLabel)

    return headerView
    }

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 60
    }
Run Code Online (Sandbox Code Playgroud)

它产生如下视图: 在此输入图像描述

我正在寻找一种方法来垂直和水平地定位UILabel视图的中心.我该怎么办?每当我改变字体和大小时它会不会改变?

另外,无论如何我会在故事板中做到这一点吗?以编程方式制作标题真的很难.

uitableview ios swift

7
推荐指数
1
解决办法
2万
查看次数

在UITableView的节标题文本下面添加一些边距

我已经设置了标题文字的样式:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as? TableViewCell

    cell!.titleLabel!.text = sections[indexPath.section].objects[indexPath.row].name
    cell!.datetimeLabel!.text = "on " + sections[indexPath.section].objects[indexPath.row].date

    return cell!
}

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
   return 100
}

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return sections[section].heading // Open Events
}
Run Code Online (Sandbox Code Playgroud)

我想在表格单元格的部分开始之前在它下面添加一些边距/填充.我添加了一些边距/填充顶部heightForHeaderInSection.有没有办法添加一些上/下边距/填充?

在此输入图像描述

uitableview ios swift

3
推荐指数
1
解决办法
5360
查看次数