我有一个UITableView,我已经创建了一个自定义单元格来显示我的表格.我显示了6个UILables,虽然我只显示了20个记录,但滚动时速度非常慢.
这就是我的 - tableView:cellForRowAtIndexPath:的样子:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = @"CustomCellIdentifier";
HistoryCell *cell = (HistoryCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HistoryCell" owner:nil options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[UITableViewCell class]])
cell = (HistoryCell *) oneObject;
}
NSArray *object;
object = [cours objectForKey: [NSString stringWithFormat:@"%d", indexPath.section]];
History *rowData = [object objectAtIndex:indexPath.row];
if (rowData.month == 99) {
cell.hour.frame = CGRectMake(10, 0, 135, 35);
cell.data.hidden = YES;
cell.hour.textColor …Run Code Online (Sandbox Code Playgroud) 我用自定义单元格创建了一个表视图,如下所示.
![自定义单元格] [1]
![出桌视图] [2]
我需要在每个单元格中使用选择器而不是滑块来设置评级

我需要设置选择器位置,只需按下按钮,它将与按钮位置相对应
如何实现它.
我尝试了fram和bounds如下,但每次都给予相同的vaues
- (IBAction) buttonClicked:(UIButton *)sender
{
NSLog(@"------%f %f",sender.frame.origin.x , sender.frame.origin.y); //250, 2
NSLog(@"------%f %f",sender.bounds.origin.x , bounds.frame.origin.y); // 0.0 , 0.0
picker.frame = CGRectMake(sender.bounds.origin.x , sender.bounds.origin.y, 50, 216);
}
Run Code Online (Sandbox Code Playgroud) 我有一个疑问,当我们选择一行或点击按钮时如何获得其他控件的值,同时具有自定义tableViewCell.假设我有一个带有TextField,Slider和按钮的TableView Cell.按钮有动作使用:
btn.tag = indexPath.row;
[btn addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
现在我可以获得其动作方法的按钮.我需要在按钮点击上获取textField的值和滑块的值.
一个选项是我创建一个数组并在该数组中存储这两个控件的值并对其进行管理.但我不认为这是管理它的正确方法.
请导航我以当前的方式获取UITableViewCell的子视图值的值.
谢谢
我对objective-c很新,对原型单元有疑问.
我有自定义单元格的tableview,它工作得很好.
现在,我也重写我的自定义单元格类-(id)init和-(id)initWithStyle: reuseIdentifier:
如果我对单元格进行类检查,它显然属于我的自定义类,但是从未调用过init方法.
所以它为我创造了它们,但不知何故避免了-(id)init对我来说似乎很奇怪的射击.
我想我可以自己创建它们,但它们似乎真的很奇怪它们可以在没有被创建的情况下存在吗?
谢谢!
我是iPhone开发的新手.我遇到了问题.我想在我的UITableView中实现一个复选框功能.但我的UITableViewCells是自定义单元格,由图像和3个UILabel组成.我可以将子视图带到表视图中,以便可以放置复选框图像,并且我成功了.但问题来的是每当我点击图像时,只有最后一个单元格复选框被更改.我想访问我点击的单元格.
我试过这个
UITableViewCell *cell = [self cellForRowAtIndexPath:indexPath]
Run Code Online (Sandbox Code Playgroud)
但是由于细胞是定制的,因此崩溃了.
任何人都可以建议我这样做的好方法吗?
我已经渲染了一个自定义单元格,它结合了图像和文本.它看起来像这样:
class ImageTextCell extends AbstractCell<String>
Run Code Online (Sandbox Code Playgroud)
我的问题是如何将此单元格添加到celltable/datagrid中.我已经厌倦了.
Column<Message, String> iconColumn = new Column<Message, String>(new ImageTextCell())
{
@Override
public String getValue(Message versionStatus) {
return ? // I dont know what to type here. How to return the ImageTextCell object }
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用自定义分隔符创建一个tableview.我制作了一个包含内容的自定义Cell,另一个只包含带分隔符的UIImageView.问题在于如何访问内容.我不能使用indexPath.row
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier: @"CustomCell"];
if(cell == nil)
{
cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] objectAtIndex:0];
}
SeparatorCell *cellSeparator = (SeparatorCell *) [tableView dequeueReusableCellWithIdentifier: @"SeparatorCell"];
if(cellSeparator == nil)
{
cellSeparator = [[[NSBundle mainBundle] loadNibNamed:@"SeparatorCell" owner:self options:nil] objectAtIndex:0];
}
if(indexPath.row % 2)
{
UIFont * myCustomFont = [UIFont fontWithName:@"Arial Black" size:16];
[cell.titulo setFont:myCustomFont];
cell.titulo.textColor = [UIColor colorWithRed:103/255.0f green:169/255.0f blue:0/255.0f alpha:1];
cell.titulo.text = [Title objectAtIndex:myRow];
cell.subtitle.text = [Subtitle objectAtIndex:myRow];
cell.tag …Run Code Online (Sandbox Code Playgroud) 我之前使用过自定义单元格,但我只想添加第三个标签(没有别的!)是否有更简单的解决方案?我想要做的就是显示标题,内容和日期.我已经将前两个设置为textLabels和detailTextLabels,但我当然需要第三个日期.
那么,如果没有自定义单元格,是否有更简单的解决方案?
谢谢
我正在尝试实现一个 UISearchController(而不是已弃用的 UISearchDisplayController)
我面临着一个可笑的时间进食问题。
当我尝试时,dequeueResusableCellWithIdentifier它不适用于我的CellAutocompletion(UITableViewCell 子类化)
像这样 :
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let item = filteredProducts[indexPath.row]
let cell:CellAutocompletion = self.tableView.dequeueReusableCellWithIdentifier("suggestionCell") as! CellAutocompletion
cell.itemLabel?.text = item.item_name;
return cell
}
Run Code Online (Sandbox Code Playgroud)
这个扔我 fatal error: unexpectedly found nil while unwrapping an Optional value
但是当我这样做时:
let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "suggestionCell");
Run Code Online (Sandbox Code Playgroud)
有用。因此,对于默认的 iOS 单元,它可以工作,而我的自定义单元则不能。任何的想法?
我想我问了错误的tableview,但考虑到我在另一个VC使用的UISearchController中包含的TableviewController中,我迷路了。
我的主要 VC实例化了我的 searchController 和出现问题的 TableViewController。
//ViewDidLoad
resultsTableController = ProductResultTabController();
resultsTableController.tableView.delegate = self;
self.searchController = UISearchController(searchResultsController: resultsTableController);
searchController.searchResultsUpdater …Run Code Online (Sandbox Code Playgroud) 在 UITableview 中向下滚动时遇到问题。当单元格被重用时,表格向我显示了具有旧内容的单元格。
问题如下:
Swift 想要重用旧单元格,但没有正确清除旧单元格中的旧内容。这会导致单元格具有旧内容,尽管我正在为单元格提供新数据。
UITableView 的架构,如果如下:
问题截图:
问卷开始截图:

向下滚动的表格:

这里的问题是“Handedness”-Cell,它显示了单元格编号 3(因为单元格的重用),这是不对的
numberOfSection-方法
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
Run Code Online (Sandbox Code Playgroud)
numberOfRowsInSection-方法
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if(section == 0){
return questionnaireStructure.count
} else {
return 1
}
}
Run Code Online (Sandbox Code Playgroud)
cellForRowAt 方法
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// first section is the normal Questionnaire
if(indexPath.section == 0){
// current questionnaireStructure
let …Run Code Online (Sandbox Code Playgroud) custom-cell ×10
uitableview ×8
iphone ×5
ios ×3
objective-c ×3
swift ×2
cell ×1
cgrect ×1
datagrid ×1
frame ×1
gwt ×1
ios5 ×1
uistoryboard ×1
xcode4.3 ×1