小编use*_*353的帖子

iOS Swift viewForHeaderInSection未被调用

我有一个UITableview我试图添加HeaderView到我的UITableview.

但是没有调用viewForHeaderInSection,但我看到正在调用或显示titleForHeaderInSection.我也尝试使用自定义单元格标题,它也不起作用.

我不知道我做错了什么.

override func viewDidLoad() {
    super.viewDidLoad()

    self.title = "Groceries"

    tableView.registerNib(UINib(nibName: "TransactionSpecifiedCategoriesTableViewCell", bundle: nil), forCellReuseIdentifier: "TransactionSpecifiedCategoriesTableViewCell")
    tableView.registerNib(UINib(nibName: "TransactionSpecifiedCategoriesHeaderViewCell", bundle: nil), forHeaderFooterViewReuseIdentifier: "TransactionSpecifiedCategoriesHeaderViewCell")
    tableView.tableFooterView = UIView(frame: CGRectMake(0, 0, 0, 0))
}

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 100))

    footerView.backgroundColor = UIColor.blackColor()

    return footerView

      //let header: UITableViewHeaderFooterView = view as UITableViewHeaderFooterView
     //var headerView = UIView(frame: CGRectMake(0, 0, 100, 320))
    //headerView.backgroundColor = UIColor.blackColor()
    //        
    //return headerView
}

func …
Run Code Online (Sandbox Code Playgroud)

uitableview xib ios swift

18
推荐指数
3
解决办法
2万
查看次数

迅速.选中后更改自定义Tableview单元格标签的颜色

Tableview在swift中有一个Custom 单元格,在该单元格中有一个标签.

我希望能够在选择单元格时更改标签.

如何在中引用我的自定义UITableviewCell标签didSelectRowAtIndexPath

在Objective C中引用我的自定义单元格,didSelectRowAtIndexPath我将使用以下内容:

MPSurveyTableViewCell *cell = (MPSurveyTableViewCell *)[tableViewcellForRowAtIndexPath:indexPath];
cell.customLabel.TextColor = [UIColor redColor]; 
Run Code Online (Sandbox Code Playgroud)

我必须在swift中做些什么才能达到相同的效果?

uitableview custom-cell didselectrowatindexpath ios swift

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

Swift - 如何在UITableview中获取所选行的数值

UITableview在Swift中制作了多个选项,并声明了一个包含NSIndexPaths所选UITableView单元格的数组.

self.selectedRows = self.preferencesTableView.indexPathsForSelectedRows()
Run Code Online (Sandbox Code Playgroud)

如何将此数组转换为可读术语.例如self.selectedRows是NSloglike:

选定项目字符串[{length = 2,path = 0 - 1},{length = 2,path = 0 - 0},{length = 2,path = 0 - 3}]

我希望能够将其转换为:1,2,3.

在Objective CI中通过数组enumerateObjectsWithOptions并将数组的id添加到可变数组中以获得我想要的内容.

[self.selectedRows enumerateObjectsWithOptions:NSEnumerationReverse
usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSIndexPath *indexPath = obj;
        [self.selectedCategorieItems addObject:[[[self.categoryArr
objectAtIndex:0] objectForKey:@"id"]objectAtIndex:indexPath.row]];
    }];
Run Code Online (Sandbox Code Playgroud)

我如何在Swift中执行此操作?

selectedindex uitableview multipleselection ios swift

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

Swift将第二个项目追加到Array

我有一个快速数组“ Monthdata”,我想在我的months数组中附加第二个值。

var monthData = []
let months = ["Jul 12","Aug 12","Sep 12","Oct 12"]

for month in months {
 self.monthData.append(month)
}
Run Code Online (Sandbox Code Playgroud)

所以基本上我的monthData数组看起来像:

["Aug 12","Oct 12"]
Run Code Online (Sandbox Code Playgroud)

arrays enumeration append ios swift

5
推荐指数
1
解决办法
2669
查看次数

Swift中的UIFont Class Crashed应用程序

我有一个UIFont类,看起来像这样:

struct FontHelper {
    func defaultFont(size: CGFloat) -> UIFont {
        return UIFont(name:"Helvetica", size: size)!
    }
}
Run Code Online (Sandbox Code Playgroud)

我称之为这样的方法"

let fonts = FontHelper.defaultFont(12)
Run Code Online (Sandbox Code Playgroud)

然而,我的应用程序崩溃与意外发现nil包装可选?

不明白为什么?

class uifont ios swift

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